Map

Trait Map 

Source
pub trait Map<K, V> {
    // Required methods
    fn len(&self) -> usize;
    fn clear(&mut self);
    fn get<Q>(&self, k: &Q) -> Option<&V>
       where K: Hash + Eq + Borrow<Q>,
             Q: ?Sized + Hash + Eq;
    fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
       where K: Hash + Eq + Borrow<Q>,
             Q: ?Sized + Hash + Eq;
    fn insert<T: Into<V>>(&mut self, k: K, v: T) -> Result<(), (K, T)>
       where K: Hash + Eq;
    fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
       where K: Hash + Eq + Borrow<Q>,
             Q: ?Sized + Hash + Eq;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn contains_key<Q>(&self, k: &Q) -> bool
       where K: Hash + Eq + Borrow<Q>,
             Q: ?Sized + Hash + Eq { ... }
    fn remove<Q>(&mut self, k: &Q) -> Option<V>
       where K: Hash + Eq + Borrow<Q>,
             Q: ?Sized + Hash + Eq { ... }
}
Expand description

An interface to the hash map operations used by KeyNodeList.

Any data structure that implements this trait can be used as the underlying hash map for KeyNodeList.

Required Methods§

Source

fn len(&self) -> usize

Returns the number of elements in the map.

This operation should compute in O(1) time.

Source

fn clear(&mut self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Source

fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

This operation should compute in O(1) time on average.

Source

fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

This operation should compute in O(1) time on average.

Source

fn insert<T: Into<V>>(&mut self, k: K, v: T) -> Result<(), (K, T)>
where K: Hash + Eq,

Inserts a key-value pair into the map.

If the map did have this key present, returns an error containing the key and the value.

If the map did not have this key present, the key-value pair is inserted, and Ok(()) is returned.

This operation should compute in O(1) time on average.

Source

fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

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

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

This operation should compute in O(1) time on average.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the map contains no elements.

This operation should compute in O(1) time.

Source

fn contains_key<Q>(&self, k: &Q) -> bool
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

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

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

This operation should compute in O(1) time on average.

Source

fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

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

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

This operation should compute in O(1) time on average.

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.

Implementations on Foreign Types§

Source§

impl<K, V> Map<K, V> for HashMap<K, V>

Source§

fn len(&self) -> usize

Source§

fn clear(&mut self)

Source§

fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

Source§

fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

Source§

fn insert<T: Into<V>>(&mut self, k: K, v: T) -> Result<(), (K, T)>
where K: Hash + Eq,

Source§

fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq,

Implementors§