pub trait SequenceHint: Sized + Sealed {
// Required method
fn get(self) -> Option<usize>;
// Provided methods
fn require<C>(self, cx: C) -> Result<usize, C::Error>
where C: Context { ... }
fn size_hint(self) -> SizeHint { ... }
}Expand description
A size hint passed in when encoding or decoding a sequence.
§Examples
use musli_core::hint::SequenceHint;
fn get_sequence_size<H>(hint: H) -> Option<usize>
where
H: SequenceHint,
{
hint.get()
}
// Known size hint
let size = get_sequence_size(10usize);
assert_eq!(size, Some(10));
// Optional size hint with value
let size = get_sequence_size(Some(7usize));
assert_eq!(size, Some(7));
// Optional size hint without value
let size = get_sequence_size(None::<usize>);
assert_eq!(size, None);Required Methods§
Provided Methods§
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.