Trait Serializer

Source
pub trait Serializer:
    Clone
    + Send
    + Sync
    + 'static
    + Sealed {
    type Format: Clone + Send + Sync + 'static;

    // Required methods
    fn lookup(&self, name: &str) -> Option<ContentType<Self::Format>>;
    fn serialize<T>(
        &self,
        value: &T,
        format: &Self::Format,
        context: &SerializerContext<'_>,
    ) -> Result<Bytes, Error>
       where T: Serialize;
}
Expand description

Serialize an HTTP response body

Serializer values use one or more Serde serializers to perform the actual serialization.

The Serializer values are also responsible for mapping content-type values to Serde serializers.

Required Associated Types§

Source

type Format: Clone + Send + Sync + 'static

A token used by Serializer implementations to identify the specific serialization format to use when encoding a value.

Required Methods§

Source

fn lookup(&self, name: &str) -> Option<ContentType<Self::Format>>

Lookup a serializer and HeaderValue for the given Content-Type string.

Source

fn serialize<T>( &self, value: &T, format: &Self::Format, context: &SerializerContext<'_>, ) -> Result<Bytes, Error>
where T: Serialize,

Serialize the value using the specified format.

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.

Implementations on Foreign Types§

Source§

impl Serializer for ()

Source§

type Format = Void

Source§

fn lookup(&self, _: &str) -> Option<ContentType<Self::Format>>

Source§

fn serialize<T>( &self, _: &T, _: &Self::Format, _: &SerializerContext<'_>, ) -> Result<Bytes, Error>
where T: Serialize,

Source§

impl<T, U> Serializer for (T, U)
where T: Serializer, U: Serializer,

Source§

type Format = Either2<<T as Serializer>::Format, <U as Serializer>::Format>

Source§

fn lookup(&self, name: &str) -> Option<ContentType<Self::Format>>

Source§

fn serialize<V>( &self, value: &V, format: &Self::Format, context: &SerializerContext<'_>, ) -> Result<Bytes, Error>
where V: Serialize,

Implementors§