pub trait Encode<T: ?Sized> {
type Encoder<'a>: Encoder
where T: 'a;
// Required method
fn encode(t: &T) -> Self::Encoder<'_>;
// Provided method
fn encode_as_value(t: &T) -> Value { ... }
}
Expand description
The trait encodes the type to the bytes and passes it to the Encoder
,
which stores it and provides a reference to it. That allows gives more
flexibility and more performant encoding, allowing the use of slices and arrays
instead of vectors in some cases. Since the Encoder
returns Cow<[u8]>
,
it is always possible to take ownership of the serialized value.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn encode_as_value(t: &T) -> Value
fn encode_as_value(t: &T) -> Value
Returns the serialized object as an Value
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.