Crates.io | have_len |
lib.rs | have_len |
version | 0.1.0 |
source | src |
created_at | 2024-10-29 14:37:24.636264 |
updated_at | 2024-10-29 14:37:24.636264 |
description | Is the container empty ? (`is_empty()` and `is_not_empty()`) |
homepage | |
repository | https://github.com/Thomas-Mewily/have_len |
max_upload_size | |
id | 1427082 |
size | 5,145 |
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() }
}