pub trait Writer {
type Value;
type Error: Error + From<Error> + From<Error> + From<Error> + Send + Sync + 'static;
type Vec: Default;
type Map: Default;
type Nested<'a>: Writer<Value = Self::Value, Error = Self::Error, Vec = Self::Vec, Map = Self::Map>
where Self: 'a;
// Required methods
fn nest(&mut self) -> Result<Self::Nested<'_>, Self::Error>;
fn write_null(&mut self) -> Result<Self::Value, Self::Error>;
fn write_bool(&mut self, value: bool) -> Result<Self::Value, Self::Error>;
fn write_number(&mut self, value: u32) -> Result<Self::Value, Self::Error>;
fn write_str(&mut self, value: String) -> Result<Self::Value, Self::Error>;
fn write_vec(
&mut self,
value: Self::Vec,
) -> Result<Self::Value, Self::Error>;
fn write_map(
&mut self,
value: Self::Map,
) -> Result<Self::Value, Self::Error>;
fn vec_push_element(
&mut self,
vec: &mut Self::Vec,
val: Self::Value,
) -> Result<(), Self::Error>;
fn map_push_field(
&mut self,
map: &mut Self::Map,
key: String,
val: Self::Value,
) -> Result<(), Self::Error>;
}Expand description
A trait for serializing Move values into some nested structured representation that supports
null, bool, numbers, strings, vectors, and maps (e.g. JSON or Protobuf).
Writers are allowed to fail, e.g. to limit resource usage.
Required Associated Types§
type Value
type Error: Error + From<Error> + From<Error> + From<Error> + Send + Sync + 'static
type Vec: Default
type Map: Default
type Nested<'a>: Writer<Value = Self::Value, Error = Self::Error, Vec = Self::Vec, Map = Self::Map> where Self: 'a
Required Methods§
Sourcefn nest(&mut self) -> Result<Self::Nested<'_>, Self::Error>
fn nest(&mut self) -> Result<Self::Nested<'_>, Self::Error>
Produce a new writer for writing into nested contexts (e.g. fields of structs or enum variants, or elements of vectors).
Sourcefn write_null(&mut self) -> Result<Self::Value, Self::Error>
fn write_null(&mut self) -> Result<Self::Value, Self::Error>
Write a null value.
Sourcefn write_bool(&mut self, value: bool) -> Result<Self::Value, Self::Error>
fn write_bool(&mut self, value: bool) -> Result<Self::Value, Self::Error>
Write a true or false value.
Sourcefn write_number(&mut self, value: u32) -> Result<Self::Value, Self::Error>
fn write_number(&mut self, value: u32) -> Result<Self::Value, Self::Error>
Write a numeric value that fits in a u32.
Sourcefn write_str(&mut self, value: String) -> Result<Self::Value, Self::Error>
fn write_str(&mut self, value: String) -> Result<Self::Value, Self::Error>
Write a string value.
Sourcefn write_vec(&mut self, value: Self::Vec) -> Result<Self::Value, Self::Error>
fn write_vec(&mut self, value: Self::Vec) -> Result<Self::Value, Self::Error>
Write a completed vector.
Sourcefn write_map(&mut self, value: Self::Map) -> Result<Self::Value, Self::Error>
fn write_map(&mut self, value: Self::Map) -> Result<Self::Value, Self::Error>
Write a completed key-value map.
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.