pub trait HasSome {
// Required methods
fn has_some(&self) -> bool;
fn is_empty2(self: &&Self) -> bool;
// Provided methods
fn is_empty3(self: &&&Self) -> bool { ... }
fn has_some2(self: &&Self) -> bool { ... }
fn has_some3(self: &&&Self) -> bool { ... }
}Required Methods§
Sourcefn has_some(&self) -> bool
fn has_some(&self) -> bool
The opposite to T:is_empty.
Usually implemented as !self.is_empty(), but as that method
is not defined by a Trait in stable Rust, this needs re-implementing
for each type that requires it.
§Examples
use has_some::HasSome;
assert!("this is not empty".has_some());use has_some::HasSome;
let vector = vec!["some_data".to_owned(), "".to_owned(), "more data".to_owned()];
let not_empties: Vec<String> = vector.into_iter().filter(String::has_some).collect();
assert_eq!(["some_data","more data"], not_empties.as_slice());Sourcefn is_empty2(self: &&Self) -> bool
fn is_empty2(self: &&Self) -> bool
is_empty in a form that is suitable for use in Iterator::filter where
Item = &OwnedType (e.g. &String)
§Examples
use has_some::HasSome;
let vector = vec!["some_data".to_owned(), "".to_owned(), "more data".to_owned()];
let empties: Vec<&String> = vector.iter().filter(String::is_empty2).collect();
assert_eq!([""], empties.as_slice());Provided Methods§
Sourcefn is_empty3(self: &&&Self) -> bool
fn is_empty3(self: &&&Self) -> bool
is_empty in a form that is suitable for use in Iterator::filter where
Item = &RefType (e.g. &&str)
§Examples
use has_some::HasSome;
let vector = vec!["some_data", "", "more data"];
let empties: Vec<&&str> = vector.iter().filter(str::is_empty3).collect();
assert_eq!([&""], empties.as_slice());Sourcefn has_some2(self: &&Self) -> bool
fn has_some2(self: &&Self) -> bool
has_some in a form that is suitable for use in Iterator::filter where
Item = &OwnedType (e.g. &String)
§Examples
use has_some::HasSome;
let vector = vec!["some_data".to_owned(), "".to_owned(), "more data".to_owned()];
let not_empties: Vec<&String> = vector.iter().filter(String::has_some2).collect();
assert_eq!(["some_data","more data"], not_empties.as_slice());Sourcefn has_some3(self: &&&Self) -> bool
fn has_some3(self: &&&Self) -> bool
has_some in a form that is suitable for use in Iterator::filter where
Item = &RefType (e.g. &&str)
§Examples
use has_some::HasSome;
let vector = vec!["some_data", "", "more data"];
let not_empties: Vec<&&str> = vector.iter().filter(str::has_some3).collect();
assert_eq!([&"some_data", &"more data"], not_empties.as_slice());Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.