pub trait UnsizedVisitor<'de, C: ?Sized + Context, T>: Sized{
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§
Required Methods§
Provided Methods§
Sourcefn visit_owned(self, cx: &C, value: T::Owned) -> Result<Self::Ok, C::Error>
fn visit_owned(self, cx: &C, value: T::Owned) -> Result<Self::Ok, C::Error>
Visit an owned value.
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.