Skip to main content

MapHint

Trait MapHint 

Source
pub trait MapHint: 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 map.

§Examples

use musli_core::hint::MapHint;

fn get_map_size<H>(hint: H) -> Option<usize>
where
    H: MapHint,
{
    hint.get()
}

// Known size hint
let size = get_map_size(5usize);
assert_eq!(size, Some(5));

// Optional size hint with value
let size = get_map_size(Some(3usize));
assert_eq!(size, Some(3));

// Optional size hint without value
let size = get_map_size(None::<usize>);
assert_eq!(size, None);

Required Methods§

Source

fn get(self) -> Option<usize>

Get an optional map hint.

Provided Methods§

Source

fn require<C>(self, cx: C) -> Result<usize, C::Error>
where C: Context,

Require a map hint or raise an error indicating that the format doesn’t support maps of unknown size if one is not present.

Source

fn size_hint(self) -> SizeHint

Coerce into a [SizeHint].

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl MapHint for Option<usize>

Source§

fn get(self) -> Option<usize>

Source§

impl MapHint for usize

Source§

fn get(self) -> Option<usize>

Source§

fn require<C>(self, _: C) -> Result<usize, C::Error>
where C: Context,

Source§

fn size_hint(self) -> SizeHint

Implementors§