pub struct SerializeRef<'a> { /* private fields */ }Expand description
A reference to a value that is serialized.
This is the type erased form of a Serialize value (and an adapter
if it’s serialized with one). The serializers of the data formats
receive the values as references, for instance from the
SerializeDriver. The methods of the
reference invoke the ones of Serialize.
use deser::adapters::DisplayFromStr;
use deser::ser::SerializeRef;
let value = 42u32;
assert!(!SerializeRef::new(&value).is_optional());
// serializes as string
let value = SerializeRef::serialize_as::<DisplayFromStr, _>(&value);Deserialization has no equivalent: values are type erased by creating
their Sink (see
Deserialize::deserialize_into),
which is already in the middle of deserializing them.
Implementations§
Source§impl<'a> SerializeRef<'a>
impl<'a> SerializeRef<'a>
Sourcepub fn new<T: Serialize>(value: &'a T) -> SerializeRef<'a>
pub fn new<T: Serialize>(value: &'a T) -> SerializeRef<'a>
Creates a reference to a value.
Sourcepub fn serialize_as<A: Serialize<T>, T: Sync>(value: &'a T) -> SerializeRef<'a>
pub fn serialize_as<A: Serialize<T>, T: Sync>(value: &'a T) -> SerializeRef<'a>
Creates a reference to a value that is serialized with an adapter.
See adapters.
Sourcepub fn serialize(self, state: &mut State) -> Result<Emit<'a>, Error>
pub fn serialize(self, state: &mut State) -> Result<Emit<'a>, Error>
Serializes the value (see Serialize::serialize).
Sourcepub fn finish(self, state: &mut State) -> Result<(), Error>
pub fn finish(self, state: &mut State) -> Result<(), Error>
Invoked after the serialization finished (see Serialize::finish).
Sourcepub fn is_optional(self) -> bool
pub fn is_optional(self) -> bool
Checks if the value is optional (see Serialize::is_optional).
Sourcepub fn container_shape(self) -> ContainerShape
pub fn container_shape(self) -> ContainerShape
Returns the shape of the value (see Serialize::container_shape).
Sourcepub fn describe(self, d: &mut dyn Describe)
pub fn describe(self, d: &mut dyn Describe)
Describes the Rust shape of the value (see Serialize::describe).