Format

Trait Format 

Source
pub trait Format: Sized {
    type Vec: Default;
    type Map: Default;

Show 18 methods // Required methods fn is_null(&self) -> bool; fn is_bool(&self) -> bool; fn is_number(&self) -> bool; fn is_string(&self) -> bool; fn is_array(&self) -> bool; fn is_object(&self) -> bool; fn as_bool(&self) -> Option<bool>; fn as_string(&self) -> Option<&str>; fn as_array(&self) -> Option<&Self::Vec>; fn as_object(&self) -> Option<&Self::Map>; fn null<M: Meter>(meter: &mut M) -> Result<Self, MeterError>; fn bool<M: Meter>(meter: &mut M, value: bool) -> Result<Self, MeterError>; fn number<M: Meter>(meter: &mut M, value: u32) -> Result<Self, MeterError>; fn string<M: Meter>( meter: &mut M, value: String, ) -> Result<Self, MeterError>; fn vec<M: Meter>( meter: &mut M, value: Self::Vec, ) -> Result<Self, MeterError>; fn map<M: Meter>( meter: &mut M, value: Self::Map, ) -> Result<Self, MeterError>; fn vec_push_element<M: Meter>( meter: &mut M, vec: &mut Self::Vec, val: Self, ) -> Result<(), MeterError>; fn map_push_field<M: Meter>( meter: &mut M, map: &mut Self::Map, key: String, val: Self, ) -> Result<(), MeterError>;
}
Expand description

A trait for serializing values into some nested structured representation that supports null, bool, numbers, strings, vectors, and maps (e.g. JSON or Protobuf).

Formats decide both the output shape and how each output operation is charged against a meter.

Required Associated Types§

Required Methods§

Source

fn is_null(&self) -> bool

Source

fn is_bool(&self) -> bool

Source

fn is_number(&self) -> bool

Source

fn is_string(&self) -> bool

Source

fn is_array(&self) -> bool

Source

fn is_object(&self) -> bool

Source

fn as_bool(&self) -> Option<bool>

Source

fn as_string(&self) -> Option<&str>

Source

fn as_array(&self) -> Option<&Self::Vec>

Source

fn as_object(&self) -> Option<&Self::Map>

Source

fn null<M: Meter>(meter: &mut M) -> Result<Self, MeterError>

Write a null value.

Source

fn bool<M: Meter>(meter: &mut M, value: bool) -> Result<Self, MeterError>

Write a true or false value.

Source

fn number<M: Meter>(meter: &mut M, value: u32) -> Result<Self, MeterError>

Write a numeric value that fits in a u32.

Source

fn string<M: Meter>(meter: &mut M, value: String) -> Result<Self, MeterError>

Write a string value.

Source

fn vec<M: Meter>(meter: &mut M, value: Self::Vec) -> Result<Self, MeterError>

Write a completed vector.

Source

fn map<M: Meter>(meter: &mut M, value: Self::Map) -> Result<Self, MeterError>

Write a completed key-value map.

Source

fn vec_push_element<M: Meter>( meter: &mut M, vec: &mut Self::Vec, val: Self, ) -> Result<(), MeterError>

Add an element to a vector.

Source

fn map_push_field<M: Meter>( meter: &mut M, map: &mut Self::Map, key: String, val: Self, ) -> Result<(), MeterError>

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.

Implementations on Foreign Types§

Source§

impl Format for Value

Source§

type Vec = Vec<Value>

Source§

type Map = Map<String, Value>

Source§

fn is_null(&self) -> bool

Source§

fn is_bool(&self) -> bool

Source§

fn is_number(&self) -> bool

Source§

fn is_string(&self) -> bool

Source§

fn is_array(&self) -> bool

Source§

fn is_object(&self) -> bool

Source§

fn as_bool(&self) -> Option<bool>

Source§

fn as_string(&self) -> Option<&str>

Source§

fn as_array(&self) -> Option<&Self::Vec>

Source§

fn as_object(&self) -> Option<&Self::Map>

Source§

fn null<M: Meter>(meter: &mut M) -> Result<Self, MeterError>

Source§

fn bool<M: Meter>(meter: &mut M, value: bool) -> Result<Self, MeterError>

Source§

fn number<M: Meter>(meter: &mut M, value: u32) -> Result<Self, MeterError>

Source§

fn string<M: Meter>(meter: &mut M, value: String) -> Result<Self, MeterError>

Source§

fn vec<M: Meter>(meter: &mut M, value: Self::Vec) -> Result<Self, MeterError>

Source§

fn map<M: Meter>(meter: &mut M, value: Self::Map) -> Result<Self, MeterError>

Source§

fn vec_push_element<M: Meter>( meter: &mut M, vec: &mut Self::Vec, value: Self, ) -> Result<(), MeterError>

Source§

fn map_push_field<M: Meter>( meter: &mut M, map: &mut Self::Map, key: String, value: Self, ) -> Result<(), MeterError>

Source§

impl Format for Value

Source§

type Vec = Vec<Value>

Source§

type Map = Struct

Source§

fn is_null(&self) -> bool

Source§

fn is_bool(&self) -> bool

Source§

fn is_number(&self) -> bool

Source§

fn is_string(&self) -> bool

Source§

fn is_array(&self) -> bool

Source§

fn is_object(&self) -> bool

Source§

fn as_bool(&self) -> Option<bool>

Source§

fn as_string(&self) -> Option<&str>

Source§

fn as_array(&self) -> Option<&Self::Vec>

Source§

fn as_object(&self) -> Option<&Self::Map>

Source§

fn null<M: Meter>(meter: &mut M) -> Result<Self, MeterError>

Source§

fn bool<M: Meter>(meter: &mut M, value: bool) -> Result<Self, MeterError>

Source§

fn number<M: Meter>(meter: &mut M, value: u32) -> Result<Self, MeterError>

Source§

fn string<M: Meter>(meter: &mut M, value: String) -> Result<Self, MeterError>

Source§

fn vec<M: Meter>(meter: &mut M, value: Self::Vec) -> Result<Self, MeterError>

Source§

fn map<M: Meter>(meter: &mut M, value: Self::Map) -> Result<Self, MeterError>

Source§

fn vec_push_element<M: Meter>( _meter: &mut M, vec: &mut Self::Vec, value: Self, ) -> Result<(), MeterError>

Source§

fn map_push_field<M: Meter>( meter: &mut M, map: &mut Self::Map, key: String, value: Self, ) -> Result<(), MeterError>

Implementors§