Enum managed::ManagedMap

source ·
pub enum ManagedMap<'a, K: 'a, V: 'a> {
    Borrowed(&'a mut [Option<(K, V)>]),
    Owned(BTreeMap<K, V>),
}
Expand description

A managed map.

This enum can be used to represent exclusive access to maps. In Rust, exclusive access to an object is obtained by either owning the object, or owning a mutable pointer to the object; hence, “managed”.

The purpose of this enum is providing good ergonomics with std present while making it possible to avoid having a heap at all (which of course means that std is not present). To achieve this, the variants other than Borrow are only available when the corresponding feature is opted in.

Unlike Managed and ManagedSlice, the managed map is implemented using a B-tree map when allocation is available, and a sorted slice of key-value pairs when it is not. Thus, algorithmic complexity of operations on it depends on the kind of map.

A function that requires a managed object should be generic over an Into<ManagedMap<'a, T>> argument; then, it will be possible to pass either a Vec<T>, or a &'a mut [T] without any conversion at the call site.

See also Managed.

Variants§

§

Borrowed(&'a mut [Option<(K, V)>])

Borrowed variant.

§

Owned(BTreeMap<K, V>)

Owned variant, only available with the std or alloc feature enabled.

Implementations§

source§

impl<'a, K: Ord + 'a, V: 'a> ManagedMap<'a, K, V>

source

pub fn clear(&mut self)

source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn range<'b, 'c, Q, R>(&'b self, range: R) -> Range<'a, K, V>
where K: Borrow<Q>, Q: Ord + ?Sized + 'c, R: RangeBounds<Q>, 'b: 'a,

source

pub fn insert(&mut self, key: K, new_value: V) -> Result<Option<V>, (K, V)>

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn is_empty(&self) -> bool

ManagedMap contains no elements?

source

pub fn len(&self) -> usize

Returns the number of elements in the ManagedMap.

source

pub fn iter(&self) -> Iter<'_, K, V>

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Trait Implementations§

source§

impl<'a, K, V> Debug for ManagedMap<'a, K, V>
where K: Debug + 'a, V: Debug + 'a,

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a, K: 'a, V: 'a> From<&'a mut [Option<(K, V)>]> for ManagedMap<'a, K, V>

source§

fn from(value: &'a mut [Option<(K, V)>]) -> Self

Converts to this type from the input type.
source§

impl<'a, K: 'a, V: 'a> From<BTreeMap<K, V>> for ManagedMap<'a, K, V>

source§

fn from(value: BTreeMap<K, V>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, K, V> Freeze for ManagedMap<'a, K, V>

§

impl<'a, K, V> RefUnwindSafe for ManagedMap<'a, K, V>
where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<'a, K, V> Send for ManagedMap<'a, K, V>
where K: Send, V: Send,

§

impl<'a, K, V> Sync for ManagedMap<'a, K, V>
where K: Sync, V: Sync,

§

impl<'a, K, V> Unpin for ManagedMap<'a, K, V>

§

impl<'a, K, V> !UnwindSafe for ManagedMap<'a, K, V>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.