1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/// A collection with a length. pub trait Len { /// Returns the length of the collection. fn len(&self) -> usize; /// Returns whether the collection is empty. fn is_empty(&self) -> bool { self.len() == 0 } } /// A mutable collection which can be cleared. pub trait LenZero: Len { /// Empties the collection, making its length zero. fn clear(&mut self); } /// A mutable collection with a length. pub trait LenMut: LenZero { /// Truncates the collection so that it is no greater than `len` long. fn truncate(&mut self, len: usize); }