Trait WeakTrue

Source
pub trait WeakTrue {
    // Required method
    fn weak_true(&self) -> bool;

    // Provided methods
    fn weak_false(&self) -> bool { ... }
    fn weak_then<F, R>(&self, f: F) -> Option<R>
       where F: FnOnce() -> R,
             Self: Sized { ... }
    fn weak_else<F, R>(&self, f: F) -> Option<R>
       where F: FnOnce() -> R,
             Self: Sized { ... }
}
Expand description

Similar to the automatic implicit conversion to boolean values in weakly typed languages

typeimpl
floatself is not 0.0 / NaN
integerself != 0
reference / smart pointerinner value impl
raw pointer!self.is_null
Optionself.is_some
Resultself.is_ok
Pollself.is_ready
str / slice / array!self.is_empty
collections!self.is_empty
unitfalse
boolself
fn / tuple / chartrue

Required Methods§

Source

fn weak_true(&self) -> bool

Similar to the automatic implicit conversion to boolean values in weakly typed languages

§Examples

assert!("c".weak_true());
assert!('c'.weak_true());
assert!('\0'.weak_true());
assert!([0].weak_true());
assert!((&0 as *const i32).weak_true());
assert!(Some(0).weak_true());

assert!(f64::NAN.weak_false());
assert!(0.0.weak_false());
assert!(0.weak_false());
assert!("".weak_false());
assert!([0; 0].weak_false());

Refer to the documentation on WeakTrue

Provided Methods§

Source

fn weak_false(&self) -> bool

Default implementation is weak_true inversion

Source

fn weak_then<F, R>(&self, f: F) -> Option<R>
where F: FnOnce() -> R, Self: Sized,

Run bool::then on WeakTrue::weak_true

§Examples

assert_eq!(1.weak_then(|| "a"), Some("a"));
assert_eq!(0.weak_then(|| "a"), None);
Source

fn weak_else<F, R>(&self, f: F) -> Option<R>
where F: FnOnce() -> R, Self: Sized,

Run bool::then on WeakTrue::weak_false

§Examples

assert_eq!(1.weak_else(|| "a"), None);
assert_eq!(0.weak_else(|| "a"), Some("a"));

Implementations on Foreign Types§

Source§

impl WeakTrue for Infallible

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for bool

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for char

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for f32

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for f64

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for i8

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for i16

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for i32

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for i64

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for i128

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for isize

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for str

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for u8

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for u16

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for u32

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for u64

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for u128

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for ()

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for usize

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for CString

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for String

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for CStr

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for OsStr

Source§

fn weak_true(&self) -> bool

Source§

impl WeakTrue for OsString

Source§

fn weak_true(&self) -> bool

Source§

impl<K> WeakTrue for BinaryHeap<K>

Source§

fn weak_true(&self) -> bool

Source§

impl<K, V> WeakTrue for BTreeMap<K, V>

Source§

fn weak_true(&self) -> bool

Source§

impl<K, V, H> WeakTrue for HashMap<K, V, H>

Source§

fn weak_true(&self) -> bool

Source§

impl<R> WeakTrue for fn() -> R

Source§

fn weak_true(&self) -> bool

Source§

impl<T> WeakTrue for Option<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T> WeakTrue for Poll<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T> WeakTrue for [T]

Source§

fn weak_true(&self) -> bool

Source§

impl<T> WeakTrue for BTreeSet<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T> WeakTrue for LinkedList<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T> WeakTrue for VecDeque<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T> WeakTrue for Vec<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T, E> WeakTrue for Result<T, E>

Source§

fn weak_true(&self) -> bool

Source§

impl<T, H> WeakTrue for HashSet<T, H>

Source§

fn weak_true(&self) -> bool

Source§

impl<T, const N: usize> WeakTrue for [T; N]

Source§

fn weak_true(&self) -> bool

Source§

impl<T: Deref> WeakTrue for Pin<T>
where T::Target: WeakTrue,

Source§

fn weak_true(&self) -> bool

Source§

impl<T: WeakTrue + ?Sized + ToOwned> WeakTrue for Cow<'_, T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T: WeakTrue + ?Sized> WeakTrue for &T

Source§

fn weak_true(&self) -> bool

Source§

impl<T: WeakTrue + ?Sized> WeakTrue for &mut T

Source§

fn weak_true(&self) -> bool

Source§

impl<T: WeakTrue + ?Sized> WeakTrue for Box<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T: WeakTrue + ?Sized> WeakTrue for Rc<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T: WeakTrue + ?Sized> WeakTrue for Arc<T>

Source§

fn weak_true(&self) -> bool

Source§

impl<T: ?Sized> WeakTrue for *const T

Source§

fn weak_true(&self) -> bool

Source§

impl<T: ?Sized> WeakTrue for *mut T

Source§

fn weak_true(&self) -> bool

Implementors§