[−][src]Struct defaultmap::DefaultBTreeMap
A BTreeMap
that returns a default when keys are accessed that are not present.
Implementations
impl<K: Eq + Hash + Ord, V: Clone> DefaultBTreeMap<K, V>
[src]
pub fn new(default: V) -> DefaultBTreeMap<K, V>
[src]
Creates an empty DefaultHashmap
with default
as the default for missing keys.
When the provided default
is equivalent to V::default()
it is preferred to use
DefaultBTreeMap::default()
instead.
pub fn new_with_map(default: V, map: BTreeMap<K, V>) -> DefaultBTreeMap<K, V>
[src]
Creates a DefaultBTreeMap
based on a default and an already existing BTreeMap
.
If V::default()
is the supplied default, usage of the from()
constructor or the
into()
method on the original BTreeMap
is preferred.
pub fn set_default(&mut self, new_default: V)
[src]
Changes the default value permanently or until set_default()
is called again.
pub fn get<Q: ?Sized, QB: Borrow<Q>>(&self, key: QB) -> &V where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
[src]
K: Borrow<Q>,
Q: Hash + Eq + Ord,
Returns a reference to the value stored for the provided key.
If the key is not in the DefaultBTreeMap
a reference to the default value is returned.
Usually the map[key]
method of retrieving keys is prefered over using get
directly.
This method accepts both references and owned values as the key.
pub fn get_mut(&mut self, key: K) -> &mut V
[src]
Returns a mutable reference to the value stored for the provided key.
If there is no value stored for the key the default value is first inserted for this
key before returning the reference.
Usually the map[key] = new_val
is prefered over using get_mut
directly.
This method only accepts owned values as the key.
impl<K: Eq + Hash + Ord, V: Clone> DefaultBTreeMap<K, V>
[src]
These methods simply forward to the underlying BTreeMap
, see that
documentation for
the usage of these methods.
pub fn keys(&self) -> Keys<'_, K, V>
[src]
pub fn values(&self) -> Values<'_, K, V>
[src]
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
[src]
pub fn iter(&self) -> Iter<'_, K, V>
[src]
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
[src]
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
[src]
pub fn len(&self) -> usize
[src]
pub fn is_empty(&self) -> bool
[src]
pub fn clear(&mut self)
[src]
pub fn insert(&mut self, k: K, v: V) -> Option<V>
[src]
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
[src]
K: Borrow<Q>,
Q: Hash + Eq + Ord,
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
[src]
K: Borrow<Q>,
Q: Hash + Eq + Ord,
Trait Implementations
impl<K: Clone + Eq + Hash + Ord, V: Clone> Clone for DefaultBTreeMap<K, V>
[src]
fn clone(&self) -> DefaultBTreeMap<K, V>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K: Debug + Eq + Hash + Ord, V: Debug + Clone> Debug for DefaultBTreeMap<K, V>
[src]
impl<K: Eq + Hash + Ord, V: Default + Clone> Default for DefaultBTreeMap<K, V>
[src]
fn default() -> DefaultBTreeMap<K, V>
[src]
The default()
constructor creates an empty DefaultBTreeMap with the default of V
as the default for missing keys.
This is desired default for most use cases, if your case requires a
different default you should use the new()
constructor.
impl<K: Eq + Hash + Ord, V: Eq + Clone> Eq for DefaultBTreeMap<K, V>
[src]
impl<K: Eq + Hash + Ord, V: Default + Clone> From<BTreeMap<K, V>> for DefaultBTreeMap<K, V>
[src]
fn from(map: BTreeMap<K, V>) -> DefaultBTreeMap<K, V>
[src]
If you already have a BTreeMap
that you would like to convert to a
DefaultBTreeMap
you can use the into()
method on the BTreeMap
or the
from()
constructor of DefaultBTreeMap
.
The default value for missing keys will be V::default()
,
if this is not desired DefaultBTreeMap::new_with_map()
should be used.
impl<K: Eq + Hash + Ord, V: Default + Clone> FromIterator<(K, V)> for DefaultBTreeMap<K, V>
[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
impl<'a, K: Eq + Hash + Ord, KB: Borrow<K>, V: Clone> Index<KB> for DefaultBTreeMap<K, V>
[src]
Implements the Index
trait so you can do map[key]
.
Nonmutable indexing can be done both by passing a reference or an owned value as the key.
impl<K: Eq + Hash + Ord, V: Clone> IndexMut<K> for DefaultBTreeMap<K, V>
[src]
Implements the IndexMut
trait so you can do map[key] = val
.
Mutably indexing can only be done when passing an owned value as the key.
impl<K: Eq + Hash + Ord, V: Clone> Into<BTreeMap<K, V>> for DefaultBTreeMap<K, V>
[src]
fn into(self) -> BTreeMap<K, V>
[src]
The into method can be used to convert a DefaultBTreeMap
back into a
BTreeMap
.
impl<K: PartialEq + Eq + Hash + Ord, V: PartialEq + Clone> PartialEq<DefaultBTreeMap<K, V>> for DefaultBTreeMap<K, V>
[src]
fn eq(&self, other: &DefaultBTreeMap<K, V>) -> bool
[src]
fn ne(&self, other: &DefaultBTreeMap<K, V>) -> bool
[src]
impl<K: Eq + Hash + Ord, V: Clone> StructuralEq for DefaultBTreeMap<K, V>
[src]
impl<K: Eq + Hash + Ord, V: Clone> StructuralPartialEq for DefaultBTreeMap<K, V>
[src]
Auto Trait Implementations
impl<K, V> RefUnwindSafe for DefaultBTreeMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for DefaultBTreeMap<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for DefaultBTreeMap<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V> Unpin for DefaultBTreeMap<K, V> where
K: Unpin,
V: Unpin,
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for DefaultBTreeMap<K, V> where
K: RefUnwindSafe + UnwindSafe,
V: RefUnwindSafe + UnwindSafe,
K: RefUnwindSafe + UnwindSafe,
V: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
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>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,