Skip to main content

JsonRpcSerializer

Trait JsonRpcSerializer 

Source
pub trait JsonRpcSerializer {
    type Value: Clone;

    // Required methods
    fn null() -> Self::Value;
    fn string(value: &str) -> Self::Value;
    fn number(value: i64) -> Self::Value;
    fn object(entries: Vec<(&'static str, Self::Value)>) -> Self::Value;
    fn to_compact_string(value: &Self::Value) -> String;
}
Expand description

Abstraction over a JSON serializer so the JSON-RPC envelope builders do not depend on a concrete JSON value type.

The caller binds this to its own JSON value type. The envelope builders only require constructing nulls, strings, integer numbers, and objects, plus compact serialization. Object key ordering in the emitted bytes is entirely determined by the implementor’s object and to_compact_string.

Required Associated Types§

Source

type Value: Clone

The JSON value type produced by this serializer.

Required Methods§

Source

fn null() -> Self::Value

A JSON null.

Source

fn string(value: &str) -> Self::Value

A JSON string.

Source

fn number(value: i64) -> Self::Value

A JSON number from a signed integer.

Source

fn object(entries: Vec<(&'static str, Self::Value)>) -> Self::Value

A JSON object built from the given key/value entries, in order.

Source

fn to_compact_string(value: &Self::Value) -> String

Serialize a value to a compact (whitespace-free) JSON string.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§