Trait len_trait::len::Clear
[−]
[src]
pub trait Clear: Len { fn clear(&mut self); }
A trait for clearing collections.
A collection is cleared by dropping all of its data. After clear
is called, the collection is
guaranteed to be empty.
Clearing a collection must take at most a linear amount of time and space.
Required Methods
fn clear(&mut self)
Clears the collection, dropping its elements and returning its length to zero.
Examples
use len_trait::Clear; struct Value(u32); impl Drop for Value { fn drop(&mut self) { println!("Dropped a {}", self.0) } } fn check_clear<C: Clear>(mut collection: C) { collection.clear(); assert!(collection.is_empty()); } check_clear(vec![Value(12)]); // Prints "Dropped a 12" check_clear("Hello, world!".to_string());
Implementors
impl<K: Ord, V> Clear for BTreeMap<K, V>
impl<T: Ord> Clear for BTreeSet<T>
impl<T: Ord> Clear for BinaryHeap<T>
impl<T> Clear for LinkedList<T>
impl Clear for String
impl<T> Clear for Vec<T>
impl<T> Clear for VecDeque<T>
impl Clear for OsString
impl<K: Eq + Hash, V> Clear for HashMap<K, V>
impl<T: Eq + Hash> Clear for HashSet<T>