pub trait IsEmpty {
// Required method
fn is_empty(&self) -> bool;
}Expand description
A trait defining an is_empty method for various types.
This trait provides a generic way to determine if a value of a given type can be considered “empty”. The definition of “empty” is context-specific and is implemented for common Rust types like collections, strings, booleans, and numeric types.
§Implementations:
Stringand&str: Returnstrueif the string contains no characters.Vec<T>: Returnstrueif the vector contains no elements.bool: Returnstrueif the boolean value isfalse.- Numeric types (integers and floats): Returns
trueif the value is0or0.0. Option<T>: Returnstrueif theOptionisNoneor ifSome(value)andvalueisis_empty().
§Usage
This trait is particularly useful for filtering or compacting collections where the concept of “emptiness” applies to the elements.
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl IsEmpty for &str
Implements IsEmpty for string slices (&str).
impl IsEmpty for &str
Implements IsEmpty for string slices (&str).
A &str is considered empty if its length is zero.
§Performance
This implementation directly calls the &str::is_empty() method,
which is an efficient O(1) operation.
Source§impl IsEmpty for String
Implements IsEmpty for String.
impl IsEmpty for String
Implements IsEmpty for String.
A String is considered empty if its length is zero.
§Performance
This implementation directly calls the String::is_empty() method,
which is an efficient O(1) operation.
Source§impl IsEmpty for bool
Implements IsEmpty for boolean values (bool).
impl IsEmpty for bool
Implements IsEmpty for boolean values (bool).
A bool is considered empty if its value is false.
This aligns with the common interpretation of false as “nothing” or “non-existent”
in a logical context.
§Performance
This is a direct comparison, an efficient O(1) operation.
Source§impl IsEmpty for f32
Implements IsEmpty for floating-point type $float_ty.
A float is considered empty if its value is 0.0.
impl IsEmpty for f32
Implements IsEmpty for floating-point type $float_ty.
A float is considered empty if its value is 0.0.
Source§impl IsEmpty for f64
Implements IsEmpty for floating-point type $float_ty.
A float is considered empty if its value is 0.0.
impl IsEmpty for f64
Implements IsEmpty for floating-point type $float_ty.
A float is considered empty if its value is 0.0.
Source§impl IsEmpty for i8
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for i8
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for i16
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for i16
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for i32
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for i32
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for i64
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for i64
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for i128
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for i128
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for isize
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for isize
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for u8
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for u8
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for u16
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for u16
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for u32
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for u32
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for u64
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for u64
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for u128
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for u128
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl IsEmpty for usize
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
impl IsEmpty for usize
Implements IsEmpty for integer type $int_ty.
An integer is considered empty if its value is 0.
Source§impl<T: IsEmpty> IsEmpty for Option<T>
Implements IsEmpty for Option<T>.
impl<T: IsEmpty> IsEmpty for Option<T>
Implements IsEmpty for Option<T>.
An Option<T> is considered empty if it is None or if it is Some(value)
and the value itself is is_empty(). This provides a recursive check for emptiness.
§Type Parameters
T: The type contained within theOption, which must also implementIsEmpty.
§Performance
The performance depends on the is_empty() implementation of the inner type T.
Source§impl<T> IsEmpty for Vec<T>
Implements IsEmpty for dynamic vectors (Vec<T>).
impl<T> IsEmpty for Vec<T>
Implements IsEmpty for dynamic vectors (Vec<T>).