musli_core::de

Trait UnsizedVisitor

Source
pub trait UnsizedVisitor<'de, C: ?Sized + Context, T>: Sized
where T: ?Sized + ToOwned,
{ type Ok; // Required method fn expecting(&self, f: &mut Formatter<'_>) -> Result; // Provided methods fn visit_owned(self, cx: &C, value: T::Owned) -> Result<Self::Ok, C::Error> { ... } fn visit_borrowed(self, cx: &C, value: &'de T) -> Result<Self::Ok, C::Error> { ... } fn visit_ref(self, cx: &C, _: &T) -> Result<Self::Ok, C::Error> { ... } }
Expand description

A visitor for data where we might need to borrow without copying from the underlying Decoder.

A visitor is needed with Decoder::decode_bytes and Decoder::decode_string because the caller doesn’t know if the encoding format is capable of producing references to the underlying data directly or if it needs to be processed first.

If all you want is to decode a value by reference, use the Decoder::decode_unsized method.

By requiring a visitor we ensure that the caller has to handle both scenarios, even if one involves erroring. A type like Cow is an example of a type which can comfortably handle both.

Required Associated Types§

Source

type Ok

The value produced.

Required Methods§

Source

fn expecting(&self, f: &mut Formatter<'_>) -> Result

Format an error indicating what was expected by this visitor.

Override to be more specific about the type that failed.

Provided Methods§

Source

fn visit_owned(self, cx: &C, value: T::Owned) -> Result<Self::Ok, C::Error>

Visit an owned value.

Source

fn visit_borrowed(self, cx: &C, value: &'de T) -> Result<Self::Ok, C::Error>

Visit a string that is borrowed directly from the source data.

Source

fn visit_ref(self, cx: &C, _: &T) -> Result<Self::Ok, C::Error>

Visit a value reference that is provided from the decoder in any manner possible. Which might require additional decoding work.

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.

Implementors§