have_len

Crates.iohave_len
lib.rshave_len
version0.1.0
sourcesrc
created_at2024-10-29 14:37:24.636264
updated_at2024-10-29 14:37:24.636264
descriptionIs the container empty ? (`is_empty()` and `is_not_empty()`)
homepage
repositoryhttps://github.com/Thomas-Mewily/have_len
max_upload_size
id1427082
size5,145
Thomas Mewily (Thomas-Mewily)

documentation

README

Define is_empty(&self) and is_not_empty(&self) for container that implement HaveLen, such as vector, array, string...

use have_len::*;

assert_eq!([1, 2, 3].is_empty(), false);
assert_eq!([1, 2, 3].is_not_empty(), true);

let empty_array : [i32; 0] = []; 
assert_eq!(empty_array.is_empty(), true);
assert_eq!(empty_array.is_not_empty(), false);


assert_eq!("".is_empty(), true);
assert_eq!("hello".is_empty(), false);

assert_eq!("".is_not_empty(), false);
assert_eq!("hello".is_not_empty(), true);

assert_eq!("".is_empty(), !("".is_not_empty()));
pub trait HaveLen
{
    fn len(&self) -> usize;

    fn is_empty(&self) -> bool { self.len() == 0 }
    fn is_not_empty(&self) -> bool { !self.is_empty() }
}
Commit count: 1

cargo fmt