1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/// A trait for types that have a length.
///
/// This trait provides methods to get the length of a collection-like object
/// and to check if it's empty.
pub trait GetLen {
/// Returns the number of elements in the collection.
///
/// # Returns
///
/// The number of elements in the collection.
fn len(&self) -> usize;
/// Checks if the collection is empty.
///
/// # Returns
///
/// `true` if the collection contains no elements, `false` otherwise.
#[inline]
fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl<T: GetLen> GetLen for std::sync::Arc<T> {
#[inline]
fn len(&self) -> usize {
self.as_ref().len()
}
}
impl<T: GetLen> GetLen for Box<T> {
#[inline]
fn len(&self) -> usize {
self.as_ref().len()
}
}
impl<T: GetLen> GetLen for &T {
#[inline]
fn len(&self) -> usize {
(*self).len()
}
}
impl<T: GetLen> GetLen for &mut T {
#[inline]
fn len(&self) -> usize {
(**self).len()
}
}