pub trait Serialize: Sync {
// Required method
fn serialize(&self, state: &mut State) -> Result<Chunk<'_>, Error>;
// Provided methods
fn finish(&self, _state: &mut State) -> Result<(), Error> { ... }
fn is_optional(&self) -> bool { ... }
fn describe(&self, d: &mut dyn Describe) { ... }
fn container_shape(&self) -> ContainerShape { ... }
}Expand description
A data structure that can be serialized into any data format supported by Deser.
serialize serializes the value into a Chunk. For
compound values like lists or similar, the piece contains a boxed emitter
which can be further processed to walk the embedded compound value. The
container_shape of such values is passed on
with the start event of the container.
§Thread Safety
Serializables are Sync and the emitters they create are Send. This
allows an ongoing serialization (a SerializeDriver) to move between
threads, for instance when it is suspended while the output is written
asynchronously. Types with shared ownership or interior mutability that
is not thread safe (such as Rc or RefCell) cannot be serialized.
Mutex and RwLock cannot be serialized either as the lock guard would
have to be held while the serialization moves between threads.
Required Methods§
Provided Methods§
Sourcefn finish(&self, _state: &mut State) -> Result<(), Error>
fn finish(&self, _state: &mut State) -> Result<(), Error>
Invoked after the serialization finished.
This is primarily useful to undo some state change in the serializer state at the end of the processing.
Sourcefn is_optional(&self) -> bool
fn is_optional(&self) -> bool
Checks if the current value that would be serialized represents an optional value.
This can be used by an emitter to skip over values that are currently
in the optional state. For instance Option<T> returns true here if
the value is None and the struct emitter created by the derive feature
will skip over these if #[deser(skip_serializing_optionals)] is set on
the struct.
Sourcefn describe(&self, d: &mut dyn Describe)
fn describe(&self, d: &mut dyn Describe)
Describes the Rust shape of this value.
This is only invoked by formats which want to reflect the Rust shape
of values, see Describe. The default implementation describes
nothing. Wrappers which serialize as the value they wrap should
describe themselves and then delegate to the wrapped value.
Sourcefn container_shape(&self) -> ContainerShape
fn container_shape(&self) -> ContainerShape
Returns the shape of this value if it’s a map or sequence.
The shape is passed on with the MapStart
or SeqStart event, it’s ignored for other
values. The default is ContainerShape::new.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Serialize for AtomicBool
Available on target_has_atomic=8 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicBool
target_has_atomic=8 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicI8
Available on target_has_atomic=8 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicI8
target_has_atomic=8 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicI16
Available on target_has_atomic=16 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicI16
target_has_atomic=16 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicI32
Available on target_has_atomic=32 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicI32
target_has_atomic=32 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicI64
Available on target_has_atomic=64 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicI64
target_has_atomic=64 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicIsize
Available on target_has_atomic=ptr only.The value is loaded with relaxed ordering.
impl Serialize for AtomicIsize
target_has_atomic=ptr only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicU8
Available on target_has_atomic=8 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicU8
target_has_atomic=8 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicU16
Available on target_has_atomic=16 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicU16
target_has_atomic=16 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicU32
Available on target_has_atomic=32 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicU32
target_has_atomic=32 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicU64
Available on target_has_atomic=64 only.The value is loaded with relaxed ordering.
impl Serialize for AtomicU64
target_has_atomic=64 only.The value is loaded with relaxed ordering.
Source§impl Serialize for AtomicUsize
Available on target_has_atomic=ptr only.The value is loaded with relaxed ordering.
impl Serialize for AtomicUsize
target_has_atomic=ptr only.The value is loaded with relaxed ordering.
Source§impl Serialize for BigDecimal
Available on crate feature bigdecimal only.
impl Serialize for BigDecimal
bigdecimal only.Source§impl Serialize for DateTime<FixedOffset>
Available on crate feature chrono only.
impl Serialize for DateTime<FixedOffset>
chrono only.Source§impl Serialize for Infallible
Values of Infallible do not exist, they are never serialized.
impl Serialize for Infallible
Values of Infallible do not exist, they are never serialized.
Source§impl Serialize for NaiveDateTime
Available on crate feature chrono only.
impl Serialize for NaiveDateTime
chrono only.Source§impl Serialize for OffsetDateTime
Available on crate feature time only.
impl Serialize for OffsetDateTime
time only.Source§impl Serialize for OsStr
Available on crate feature std only.Serializes as a string like Path. OS strings which are not valid
UTF-8 fail to serialize.
impl Serialize for OsStr
std only.Serializes as a string like Path. OS strings which are not valid
UTF-8 fail to serialize.
Source§impl Serialize for Path
Available on crate feature std only.Serializes as a string. Paths which are not valid UTF-8 fail to
serialize.
impl Serialize for Path
std only.Serializes as a string. Paths which are not valid UTF-8 fail to serialize.
Source§impl Serialize for PrimitiveDateTime
Available on crate feature time only.
impl Serialize for PrimitiveDateTime
time only.Source§impl Serialize for SignedDuration
Available on crate feature jiff only.
impl Serialize for SignedDuration
jiff only.Source§impl Serialize for SocketAddr
Serializes as a string (with Display).
impl Serialize for SocketAddr
Serializes as a string (with Display).
Source§impl Serialize for SocketAddrV4
Serializes as a string (with Display).
impl Serialize for SocketAddrV4
Serializes as a string (with Display).
Source§impl Serialize for SocketAddrV6
Serializes as a string (with Display).
impl Serialize for SocketAddrV6
Serializes as a string (with Display).
Source§impl Serialize for SystemTime
impl Serialize for SystemTime
Source§impl Serialize for UtcDateTime
Available on crate feature time only.
impl Serialize for UtcDateTime
time only.Source§impl<'a, T> Serialize for Cow<'a, T>
Cow<[T]> is implemented separately as slices are serialized by the
containers holding them (see serialize_slice).
impl<'a, T> Serialize for Cow<'a, T>
Cow<[T]> is implemented separately as slices are serialized by the
containers holding them (see serialize_slice).
Source§impl<T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
impl<T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
Source§impl<T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
impl<T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
Source§impl<T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
impl<T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
Source§impl<T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T4, T5, T6, T7, T8, T9, T10, T11, T12)
impl<T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T4, T5, T6, T7, T8, T9, T10, T11, T12)
Source§impl<T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T5, T6, T7, T8, T9, T10, T11, T12)
impl<T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T5, T6, T7, T8, T9, T10, T11, T12)
Source§impl<T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T6, T7, T8, T9, T10, T11, T12)
impl<T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T6, T7, T8, T9, T10, T11, T12)
Source§impl<T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T7, T8, T9, T10, T11, T12)
impl<T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T7, T8, T9, T10, T11, T12)
Source§impl<T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T8, T9, T10, T11, T12)
impl<T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T8, T9, T10, T11, T12)
Source§impl<T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T9, T10, T11, T12)
impl<T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> Serialize for (T9, T10, T11, T12)
Source§impl<T, S: Sync> Serialize for HashSet<T, S>where
T: Serialize,
Available on crate feature hashbrown only.
impl<T, S: Sync> Serialize for HashSet<T, S>where
T: Serialize,
hashbrown only.Source§impl<T, S: Sync> Serialize for IndexSet<T, S>where
T: Serialize,
Available on crate feature indexmap only.
impl<T, S: Sync> Serialize for IndexSet<T, S>where
T: Serialize,
indexmap only.Source§impl<T: Serialize + Send> Serialize for OnceLock<T>
Available on crate feature std only.Serializes like an Option: as the value if it’s set, as null if not.
impl<T: Serialize + Send> Serialize for OnceLock<T>
std only.Serializes like an Option: as the value if it’s set, as null if not.
Source§impl<T: Serialize, E: Serialize> Serialize for Result<T, E>
Serializes externally tagged: {"Ok": value} or {"Err": error}.
impl<T: Serialize, E: Serialize> Serialize for Result<T, E>
Serializes externally tagged: {"Ok": value} or {"Err": error}.
Source§impl<T: Serialize, const CAP: usize> Serialize for ArrayVec<T, CAP>
Available on crate feature arrayvec only.
impl<T: Serialize, const CAP: usize> Serialize for ArrayVec<T, CAP>
arrayvec only.Source§impl<T: Serialize, const N: usize> Serialize for SmallVec<[T; N]>
Available on crate feature smallvec only.
impl<T: Serialize, const N: usize> Serialize for SmallVec<[T; N]>
smallvec only.Source§impl<T: Serialize> Serialize for BinaryHeap<T>
The elements are emitted in the (arbitrary) order of the heap.
impl<T: Serialize> Serialize for BinaryHeap<T>
The elements are emitted in the (arbitrary) order of the heap.
Source§impl<T: Serialize> Serialize for Bound<T>
Serializes externally tagged like serde: "Unbounded", {"Included": value} or {"Excluded": value}.
impl<T: Serialize> Serialize for Bound<T>
Serializes externally tagged like serde: "Unbounded", {"Included": value} or {"Excluded": value}.
Source§impl<T: Serialize> Serialize for LinkedList<T>
impl<T: Serialize> Serialize for LinkedList<T>
Source§impl<T: Serialize> Serialize for ManuallyDrop<T>
Serializes as the inner value.
impl<T: Serialize> Serialize for ManuallyDrop<T>
Serializes as the inner value.
Source§impl<T: Serialize> Serialize for Range<T>
Serializes as a struct with start and end like serde.
impl<T: Serialize> Serialize for Range<T>
Serializes as a struct with start and end like serde.
Source§impl<T: Serialize> Serialize for RangeInclusive<T>
Serializes as a struct with start and end like serde.
impl<T: Serialize> Serialize for RangeInclusive<T>
Serializes as a struct with start and end like serde.
Source§impl<T: Serialize> Serialize for Saturating<T>
impl<T: Serialize> Serialize for Saturating<T>
Source§impl<const CAP: usize> Serialize for ArrayString<CAP>
Available on crate feature arrayvec only.
impl<const CAP: usize> Serialize for ArrayString<CAP>
arrayvec only.Implementors§
impl Serialize for deser_core::ext::BigInt
impl Serialize for Datetime
impl Serialize for deser_core::ext::Decimal
impl Serialize for deser_core::ext::Duration
impl Serialize for RecordBuf<'_>
Record buffers serialize like Recordings, borrowed atoms are
serialized without copying them.