Trait Writer

Source
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§

Source

type Value

Source

type Error: Error + From<Error> + From<Error> + From<Error> + Send + Sync + 'static

Source

type Vec: Default

Source

type Map: Default

Source

type Nested<'a>: Writer<Value = Self::Value, Error = Self::Error, Vec = Self::Vec, Map = Self::Map> where Self: 'a

Required Methods§

Source

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).

Source

fn write_null(&mut self) -> Result<Self::Value, Self::Error>

Write a null value.

Source

fn write_bool(&mut self, value: bool) -> Result<Self::Value, Self::Error>

Write a true or false value.

Source

fn write_number(&mut self, value: u32) -> Result<Self::Value, Self::Error>

Write a numeric value that fits in a u32.

Source

fn write_str(&mut self, value: String) -> Result<Self::Value, Self::Error>

Write a string value.

Source

fn write_vec(&mut self, value: Self::Vec) -> Result<Self::Value, Self::Error>

Write a completed vector.

Source

fn write_map(&mut self, value: Self::Map) -> Result<Self::Value, Self::Error>

Write a completed key-value map.

Source

fn vec_push_element( &mut self, vec: &mut Self::Vec, val: Self::Value, ) -> Result<(), Self::Error>

Add an element to a vector.

Source

fn map_push_field( &mut self, map: &mut Self::Map, key: String, val: Self::Value, ) -> Result<(), Self::Error>

Add a key-value pair to a 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.

Implementors§

Source§

impl<'b> Writer for ProtoWriter<'b>

Source§

type Value = Value

Source§

type Error = Error

Source§

type Vec = Vec<Value>

Source§

type Map = Struct

Source§

type Nested<'a> = ProtoWriter<'a> where Self: 'a