pub trait Serialize {
// Required method
fn serialize(&self, state: &SerializerState<'_>) -> Result<Chunk<'_>, Error>;
// Provided methods
fn finish(&self, _state: &SerializerState<'_>) -> Result<(), Error> { ... }
fn is_optional(&self) -> bool { ... }
fn descriptor(&self) -> &dyn Descriptor { ... }
}Expand description
A data structure that can be serialized into any data format supported by Deser.
This trait provides two things:
descriptorreturns a reference to the closest descriptor of this value. The descriptor provides auxiliary information about the value that the serialization system does not expose.serializeserializes the value into aChunk. For compound values like lists or similar, the piece contains a boxed emitter which can be further processed to walk the embedded compound value.
Required Methods§
Provided Methods§
Sourcefn finish(&self, _state: &SerializerState<'_>) -> Result<(), Error>
fn finish(&self, _state: &SerializerState<'_>) -> 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 descriptor(&self) -> &dyn Descriptor
fn descriptor(&self) -> &dyn Descriptor
Returns the descriptor of this serializable if it exists.