pub trait Len {
// Required method
fn len(&self) -> usize;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
A trait for types that have a notion of length or size.
This trait provides a standard interface for determining the number of elements
in a collection or the size of an object. It defines both a required len() method
and a default implementation of is_empty() which relies on len().
Types implementing this trait can be checked for emptiness using the is_empty()
method without requiring a separate implementation, as long as they provide
a way to determine their length.
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".