Skip to main content

BTreeMap

Struct BTreeMap 

Source
pub struct BTreeMap<K, V, const N: usize>(/* private fields */);
Expand description

An ordered map based on a B-Tree (with alloc) or a linear map (with heapless).

When heapless feature is enabled, this is a wrapper around heapless::LinearMap<K, V, N>.

Note: With heapless, iteration order is insertion order, not key order.

Implementations§

Source§

impl<K, V, const N: usize> BTreeMap<K, V, N>
where K: Ord + Eq,

Source

pub fn new() -> Self

Constructs a new, empty map.

Source

pub fn get(&self, key: &K) -> Option<&V>

Returns a reference to the value corresponding to the key.

Source

pub fn contains_key(&self, key: &K) -> bool

Returns true if the map contains a value for the specified key.

Source

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

Inserts a key-value pair into the map.

If the map did not have this key present, Ok(None) is returned. If the map did have this key present, the value is updated, and Ok(Some(old_value)) is returned. Returns Err if the map is at capacity (heapless only).

Source

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

Removes a key from the map, returning the value at the key if the key was previously in the map.

Source§

impl<K, V, const N: usize> BTreeMap<K, V, N>
where K: Eq,

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

pub fn clear(&mut self)

Clears the map, removing all elements.

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>

Returns an iterator over the map’s key-value pairs.

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

Returns an iterator over the map’s keys.

Source

pub fn values(&self) -> impl Iterator<Item = &V>

Returns an iterator over the map’s values.

Trait Implementations§

Source§

impl<K, V, const N: usize> Clone for BTreeMap<K, V, N>
where K: Clone + Eq, V: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V, const N: usize> Debug for BTreeMap<K, V, N>
where K: Debug + Eq, V: Debug,

Source§

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

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

impl<K, V, const N: usize> Default for BTreeMap<K, V, N>
where K: Ord + Eq,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V, const N: usize> Eq for BTreeMap<K, V, N>
where K: Ord + Eq, V: Eq,

Source§

impl<K, V, const N: usize> PartialEq for BTreeMap<K, V, N>
where K: Ord + Eq, V: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<K, V, const N: usize> Freeze for BTreeMap<K, V, N>

§

impl<K, V, const N: usize> RefUnwindSafe for BTreeMap<K, V, N>

§

impl<K, V, const N: usize> Send for BTreeMap<K, V, N>
where K: Send, V: Send,

§

impl<K, V, const N: usize> Sync for BTreeMap<K, V, N>
where K: Sync, V: Sync,

§

impl<K, V, const N: usize> Unpin for BTreeMap<K, V, N>

§

impl<K, V, const N: usize> UnsafeUnpin for BTreeMap<K, V, N>

§

impl<K, V, const N: usize> UnwindSafe for BTreeMap<K, V, N>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.