//! - PathBuf
//! - Range\<T\>
//! - RangeInclusive\<T\>
+//! - Bound\<T\>
//! - num::NonZero*
//! - `!` *(unstable)*
//! - **Net types**:
/// For example, a filesystem [`Path`] may refuse to serialize
/// itself if it contains invalid UTF-8 data.
///
- /// ```rust
+ /// ```edition2018
/// # struct Path;
/// #
/// # impl Path {
/// See the [Implementing `Serialize`] section of the manual for more
/// information about how to implement this method.
///
- /// ```rust
+ /// ```edition2018
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
///
/// struct Person {
/// Serialize a `bool` value.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for bool {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_bool(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>;
/// reasonable implementation would be to cast the value to `i64` and
/// forward to `serialize_i64`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for i8 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_i8(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error>;
/// reasonable implementation would be to cast the value to `i64` and
/// forward to `serialize_i64`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for i16 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_i16(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>;
/// reasonable implementation would be to cast the value to `i64` and
/// forward to `serialize_i64`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for i32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_i32(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>;
/// Serialize an `i64` value.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for i64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_i64(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>;
serde_if_integer128! {
/// Serialize an `i128` value.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for i128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_i128(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
///
/// This method is available only on Rust compiler versions >=1.26. The
/// reasonable implementation would be to cast the value to `u64` and
/// forward to `serialize_u64`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for u8 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_u8(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error>;
/// reasonable implementation would be to cast the value to `u64` and
/// forward to `serialize_u64`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for u16 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_u16(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>;
/// reasonable implementation would be to cast the value to `u64` and
/// forward to `serialize_u64`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for u32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_u32(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>;
/// Serialize a `u64` value.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for u64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_u64(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>;
serde_if_integer128! {
/// Serialize a `u128` value.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for u128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_u128(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
///
/// This method is available only on Rust compiler versions >=1.26. The
/// reasonable implementation would be to cast the value to `f64` and
/// forward to `serialize_f64`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for f32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_f32(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>;
/// Serialize an `f64` value.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for f64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_f64(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>;
/// If the format does not support characters, it is reasonable to serialize
/// it as a single element `str` or a `u32`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for char {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_char(*self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error>;
/// Serialize a `&str`.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for str {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_str(self)
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>;
/// `serialize_seq`. If forwarded, the implementation looks usually just
/// like this:
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::ser::{Serializer, SerializeSeq};
/// # use serde::private::ser::Error;
/// #
/// seq.end()
/// }
/// #
- /// # __serialize_unimplemented! {
+ /// # serde::__serialize_unimplemented! {
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str none some
/// # unit unit_struct unit_variant newtype_struct newtype_variant
/// # seq tuple tuple_struct tuple_variant map struct struct_variant
/// # }
/// # }
- /// #
- /// # fn main() {}
/// ```
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>;
/// Serialize a [`None`] value.
///
- /// ```rust
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::{Serialize, Serializer};
/// #
/// # enum Option<T> {
/// # None,
/// # }
/// #
- /// # use Option::{Some, None};
+ /// # use self::Option::{Some, None};
/// #
/// impl<T> Serialize for Option<T>
/// where
/// Serialize a [`Some(T)`] value.
///
- /// ```rust
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::{Serialize, Serializer};
/// #
/// # enum Option<T> {
/// # None,
/// # }
/// #
- /// # use Option::{Some, None};
+ /// # use self::Option::{Some, None};
/// #
/// impl<T> Serialize for Option<T>
/// where
/// Serialize a `()` value.
///
- /// ```rust
- /// # #[macro_use]
- /// # extern crate serde;
- /// #
+ /// ```edition2018
/// # use serde::Serializer;
/// #
- /// # __private_serialize!();
+ /// # serde::__private_serialize!();
/// #
/// impl Serialize for () {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// serializer.serialize_unit()
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
fn serialize_unit(self) -> Result<Self::Ok, Self::Error>;
///
/// A reasonable implementation would be to forward to `serialize_unit`.
///
- /// ```rust
+ /// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// struct Nothing;
/// this variant within the enum, and the `variant` is the name of the
/// variant.
///
- /// ```rust
+ /// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// enum E {
/// wrappers around the data they contain. A reasonable implementation would
/// be to forward to `value.serialize(self)`.
///
- /// ```rust
+ /// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// struct Millimeters(u8);
/// this variant within the enum, and the `variant` is the name of the
/// variant. The `value` is the data contained within this newtype variant.
///
- /// ```rust
+ /// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// enum E {
/// not be computable before the sequence is iterated. Some serializers only
/// support sequences whose length is known up front.
///
- /// ```rust
+ /// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct Vec<T>(PhantomData<T>);
/// This call must be followed by zero or more calls to `serialize_element`,
/// then a call to `end`.
///
- /// ```rust
+ /// ```edition2018
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
///
/// # mod fool {
/// }
/// ```
///
- /// ```rust
+ /// ```edition2018
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
///
/// const VRAM_SIZE: usize = 386;
/// The `name` is the name of the tuple struct and the `len` is the number
/// of data fields that will be serialized.
///
- /// ```rust
+ /// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
///
/// struct Rgb(u8, u8, u8);
/// this variant within the enum, the `variant` is the name of the variant,
/// and the `len` is the number of data fields that will be serialized.
///
- /// ```rust
+ /// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
///
/// enum E {
/// be computable before the map is iterated. Some serializers only support
/// maps whose length is known up front.
///
- /// ```rust
+ /// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
/// The `name` is the name of the struct and the `len` is the number of
/// data fields that will be serialized.
///
- /// ```rust
+ /// ```edition2018
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
///
/// struct Rgb {
/// this variant within the enum, the `variant` is the name of the variant,
/// and the `len` is the number of data fields that will be serialized.
///
- /// ```rust
+ /// ```edition2018
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
///
/// enum E {
/// using [`serialize_seq`]. Implementors should not need to override this
/// method.
///
- /// ```rust
+ /// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// struct SecretlyOneHigher {
/// using [`serialize_map`]. Implementors should not need to override this
/// method.
///
- /// ```rust
+ /// ```edition2018
/// use serde::{Serialize, Serializer};
/// use std::collections::BTreeSet;
///
/// delegates to [`serialize_str`]. Serializers are encouraged to provide a
/// more efficient implementation if possible.
///
- /// ```rust
+ /// ```edition2018
/// # struct DateTime;
/// #
/// # impl DateTime {
/// of this method. If no more sensible behavior is possible, the
/// implementation is expected to return an error.
///
- /// ```rust
+ /// ```edition2018
/// # struct DateTime;
/// #
/// # impl DateTime {
/// human-readable one and binary formats like Bincode will prefer the
/// compact one.
///
- /// ```
+ /// ```edition2018
/// # use std::fmt::{self, Display};
/// #
/// # struct Timestamp;
///
/// # Example use
///
-/// ```rust
+/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct Vec<T>(PhantomData<T>);
///
/// # Example use
///
-/// ```rust
+/// ```edition2018
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
///
/// # mod fool {
/// }
/// ```
///
-/// ```rust
+/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct Array<T>(PhantomData<T>);
///
/// # Example use
///
-/// ```rust
+/// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
///
/// struct Rgb(u8, u8, u8);
///
/// # Example use
///
-/// ```rust
+/// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
///
/// enum E {
///
/// # Example use
///
-/// ```rust
+/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
///
/// # Example use
///
-/// ```rust
+/// ```edition2018
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
///
/// struct Rgb {
///
/// # Example use
///
-/// ```rust
+/// ```edition2018
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
///
/// enum E {