pub trait HasSome {
fn has_some(&self) -> bool;
fn is_empty2(self: &&Self) -> bool;
fn is_empty3(self: &&&Self) -> bool {
(*self).is_empty2()
}
fn has_some2(self: &&Self) -> bool {
(*self).has_some()
}
fn has_some3(self: &&&Self) -> bool {
(*self).has_some()
}
}
impl HasSome for str {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl HasSome for ::std::ffi::CStr {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl HasSome for ::std::string::String {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<Idx: PartialOrd<Idx>> HasSome for ::std::ops::Range<Idx> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<Idx: PartialOrd<Idx>> HasSome for ::std::ops::RangeInclusive<Idx> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<K, V, S: ::std::hash::BuildHasher> HasSome for ::std::collections::hash_map::HashMap<K, V, S> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<K, V> HasSome for ::std::collections::BTreeMap<K, V> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<T, S: ::std::hash::BuildHasher> HasSome for ::std::collections::hash_set::HashSet<T, S> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<T> HasSome for [T] {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<T> HasSome for ::std::collections::BinaryHeap<T> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<T> HasSome for ::std::collections::BTreeSet<T> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<T> HasSome for ::std::collections::LinkedList<T> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<T> HasSome for ::std::collections::VecDeque<T> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
impl<T> HasSome for ::std::vec::Vec<T> {
fn has_some(&self) -> bool {
!self.is_empty()
}
fn is_empty2(self: &&Self) -> bool {
(*self).is_empty()
}
}
pub trait HasSomeConsume {
fn has_some(self) -> bool;
fn is_empty1(&self) -> bool;
fn has_some1(&self) -> bool;
}
impl<T> HasSomeConsume for ::std::ptr::NonNull<[T]> {
fn has_some(self) -> bool {
!self.is_empty()
}
fn is_empty1(&self) -> bool {
(*self).is_empty()
}
fn has_some1(&self) -> bool {
!(*self).is_empty()
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_owned_items() {
use super::HasSome;
let vector = vec![
"some_data".to_owned(),
"".to_owned(),
"more data".to_owned(),
"".to_owned(),
];
let vector2 = vector.clone();
let empties = vector
.into_iter()
.filter(String::is_empty)
.collect::<Vec<String>>();
assert_eq!(["", ""], empties.as_slice());
let non_empties = vector2
.into_iter()
.filter(String::has_some)
.collect::<Vec<String>>();
assert_eq!(["some_data", "more data"], non_empties.as_slice());
}
#[test]
fn test_ref_items() {
use super::HasSome;
let vector = vec!["some_data", "", "more data", ""];
let vector2 = vector.clone();
let empties = vector
.into_iter()
.filter(str::is_empty2)
.collect::<Vec<&str>>();
assert_eq!(["", ""], empties.as_slice());
let non_empties = vector2
.iter()
.filter(str::has_some3)
.collect::<Vec<&&str>>();
assert_eq!([&"some_data", &"more data"], non_empties.as_slice());
}
}