pub trait VisitValue<'v> {
// Required method
fn visit_any(&mut self, value: Value<'_>) -> Result<(), Error>;
// Provided methods
fn visit_null(&mut self) -> Result<(), Error> { ... }
fn visit_u64(&mut self, value: u64) -> Result<(), Error> { ... }
fn visit_i64(&mut self, value: i64) -> Result<(), Error> { ... }
fn visit_u128(&mut self, value: u128) -> Result<(), Error> { ... }
fn visit_i128(&mut self, value: i128) -> Result<(), Error> { ... }
fn visit_f64(&mut self, value: f64) -> Result<(), Error> { ... }
fn visit_bool(&mut self, value: bool) -> Result<(), Error> { ... }
fn visit_str(&mut self, value: &str) -> Result<(), Error> { ... }
fn visit_borrowed_str(&mut self, value: &'v str) -> Result<(), Error> { ... }
fn visit_char(&mut self, value: char) -> Result<(), Error> { ... }
}Expand description
A visitor for a Value.
Also see Value’s documentation on seralization. Value visitors are a simple alternative
to a more fully-featured serialization framework like serde or sval. A value visitor
can differentiate primitive types through methods like VisitValue::visit_bool and
VisitValue::visit_str, but more complex types like maps and sequences
will fallthrough to VisitValue::visit_any.
If you’re trying to serialize a value to a format like JSON, you can use either serde
or sval directly with the value. You don’t need a visitor.
Required Methods§
Sourcefn visit_any(&mut self, value: Value<'_>) -> Result<(), Error>
fn visit_any(&mut self, value: Value<'_>) -> Result<(), Error>
Visit a Value.
This is the only required method on VisitValue and acts as a fallback for any
more specific methods that aren’t overridden.
The Value may be formatted using its fmt::Debug or fmt::Display implementation,
or serialized using its sval::Value or serde::Serialize implementation.
Provided Methods§
Sourcefn visit_null(&mut self) -> Result<(), Error>
fn visit_null(&mut self) -> Result<(), Error>
Visit an empty value.