truthy

Trait Truthy

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

    // Provided methods
    fn falsy(&self) -> bool { ... }
    fn truthy_or<T>(self, other: T) -> Either<Self, T>
       where Self: Sized { ... }
    fn truthy_and<T>(self, other: T) -> Option<T>
       where Self: Sized { ... }
}
Expand description

Convert to a bool.

Required Methods§

Source

fn truthy(&self) -> bool

Converts &self to a bool.

Provided Methods§

Source

fn falsy(&self) -> bool

Not truthy

Source

fn truthy_or<T>(self, other: T) -> Either<Self, T>
where Self: Sized,

Left(self) if self is truthy, else Right(other)

assert_eq!(true.truthy_or('t').left(), Some(true));
assert_eq!(false.truthy_or('t').right(), Some('t'));
Examples found in repository?
examples/and_or.rs (line 6)
3
4
5
6
7
8
fn main() {
    println!(r#"true.truthy_and("Hi!") => {:?}"#, true.truthy_and("Hi!"));
    println!(r#"false.truthy_and("Hi!") => {:?}"#, false.truthy_and("Hi!"));
    println!(r#"true.truthy_or("Hi!") => {:?}"#, true.truthy_or("Hi!"));
    println!(r#"false.truthy_or("Hi!") => {:?}"#, false.truthy_or("Hi!"));
}
Source

fn truthy_and<T>(self, other: T) -> Option<T>
where Self: Sized,

Some(other) if self is truthy, else None

assert_eq!(true.truthy_and('t'), Some('t'));
assert_eq!(false.truthy_and('t'), None);
Examples found in repository?
examples/and_or.rs (line 4)
3
4
5
6
7
8
fn main() {
    println!(r#"true.truthy_and("Hi!") => {:?}"#, true.truthy_and("Hi!"));
    println!(r#"false.truthy_and("Hi!") => {:?}"#, false.truthy_and("Hi!"));
    println!(r#"true.truthy_or("Hi!") => {:?}"#, true.truthy_or("Hi!"));
    println!(r#"false.truthy_or("Hi!") => {:?}"#, false.truthy_or("Hi!"));
}

Implementations on Foreign Types§

Source§

impl Truthy for &str

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for bool

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for f32

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for f64

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for i8

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for i16

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for i32

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for i64

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for i128

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for isize

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for u8

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for u16

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for u32

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for u64

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for u128

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for ()

Source§

fn truthy(&self) -> bool

Source§

impl Truthy for usize

Source§

fn truthy(&self) -> bool

Source§

impl<T1> Truthy for (T1,)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2> Truthy for (T1, T2)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3> Truthy for (T1, T2, T3)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4> Truthy for (T1, T2, T3, T4)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5> Truthy for (T1, T2, T3, T4, T5)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5, T6> Truthy for (T1, T2, T3, T4, T5, T6)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5, T6, T7> Truthy for (T1, T2, T3, T4, T5, T6, T7)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8> Truthy for (T1, T2, T3, T4, T5, T6, T7, T8)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9> Truthy for (T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> Truthy for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Truthy for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

fn truthy(&self) -> bool

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Truthy for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

Source§

fn truthy(&self) -> bool

Source§

impl<T> Truthy for Option<T>
where T: Truthy,

Source§

fn truthy(&self) -> bool

Source§

impl<T> Truthy for [T]

Source§

fn truthy(&self) -> bool

Source§

impl<T, E> Truthy for Result<T, E>
where T: Truthy,

Source§

fn truthy(&self) -> bool

Implementors§