Trait Serializer

Source
pub trait Serializer<T> {
    // Required method
    fn serialize_into(&self, value: &T, builder: &mut Builder);

    // Provided methods
    fn to_value(&self, value: &T) -> Value { ... }
    fn serialize(&self, value: &T) -> String { ... }
    fn serialize_iter<'a, I>(&self, values: I) -> String
       where I: IntoIterator<Item = &'a T>,
             T: 'a { ... }
}
Expand description

The trait you implement in order to make a serializer.

Required Methods§

Source

fn serialize_into(&self, value: &T, builder: &mut Builder)

Add key-value pairs to the builder for the given object.

You shouldn’t have to call this method yourself. It’ll be called by other method in this trait.

Provided Methods§

Source

fn to_value(&self, value: &T) -> Value

Turn the given object into a serde_json::Value.

Source

fn serialize(&self, value: &T) -> String

Turn the given object into a JSON string.

Source

fn serialize_iter<'a, I>(&self, values: I) -> String
where I: IntoIterator<Item = &'a T>, T: 'a,

Turn the given iterable into JSON array. The main usecase for this is to turn Vecs into JSON arrays, but works for any iterator.

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§