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§
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>
Sourcefn bool<M: Meter>(meter: &mut M, value: bool) -> Result<Self, MeterError>
fn bool<M: Meter>(meter: &mut M, value: bool) -> Result<Self, MeterError>
Write a true or false value.
Sourcefn number<M: Meter>(meter: &mut M, value: u32) -> Result<Self, MeterError>
fn number<M: Meter>(meter: &mut M, value: u32) -> Result<Self, MeterError>
Write a numeric value that fits in a u32.
Sourcefn string<M: Meter>(meter: &mut M, value: String) -> Result<Self, MeterError>
fn string<M: Meter>(meter: &mut M, value: String) -> Result<Self, MeterError>
Write a string value.
Sourcefn vec<M: Meter>(meter: &mut M, value: Self::Vec) -> Result<Self, MeterError>
fn vec<M: Meter>(meter: &mut M, value: Self::Vec) -> Result<Self, MeterError>
Write a completed vector.
Sourcefn map<M: Meter>(meter: &mut M, value: Self::Map) -> Result<Self, MeterError>
fn map<M: Meter>(meter: &mut M, value: Self::Map) -> Result<Self, MeterError>
Write a completed key-value map.
Sourcefn vec_push_element<M: Meter>(
meter: &mut M,
vec: &mut Self::Vec,
val: Self,
) -> Result<(), MeterError>
fn vec_push_element<M: Meter>( meter: &mut M, vec: &mut Self::Vec, val: Self, ) -> Result<(), MeterError>
Add an element to a vector.
Sourcefn map_push_field<M: Meter>(
meter: &mut M,
map: &mut Self::Map,
key: String,
val: Self,
) -> Result<(), MeterError>
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.