Trait aoko::no_std::functions::ext::AnyExt[][src]

pub trait AnyExt: Sized {
Show 13 methods fn drop(self) { ... }
fn as_some(self) -> Option<Self> { ... }
fn as_ok<B>(self) -> Result<Self, B> { ... }
fn as_err<A>(self) -> Result<A, Self> { ... }
fn as_box(self) -> Box<Self> { ... }
fn as_cell(self) -> Cell<Self> { ... }
fn as_ref_cell(self) -> RefCell<Self> { ... }
fn as_rc(self) -> Rc<Self> { ... }
fn as_arc(self) -> Arc<Self> { ... }
fn type_name(&self) -> &str { ... }
fn type_size(&self) -> usize { ... }
fn take_if(self, f: impl FnOnce(&Self) -> bool) -> Option<Self> { ... }
fn take_unless(self, f: impl FnOnce(&Self) -> bool) -> Option<Self> { ... }
}
Expand description

This trait is to implement some extension functions for any sized type.

Provided methods

Chainable drop

Convert value to Some(value)

Convert value to Ok(value)

Convert value to Err(value)

Convert value to Box::new(value)

Convert value to Cell(value)

Convert value to RefCell(value)

Convert value to Rc::new(value)

Convert value to Arc::new(value)

Returns the name of a type as a string slice.

Examples
use aoko::no_std::functions::ext::*;

assert_eq!("".type_name(), "&str");     // auto ref, auto deref.
assert_eq!((&"").type_name(), "&str");  // auto deref.
assert_eq!((&&"").type_name(), "&&str");

Returns the size of a type in bytes.

Examples
use aoko::no_std::functions::ext::*;

assert_eq!(().type_size(), 0);      // auto ref, auto deref.
assert_eq!((&()).type_size(), 0);   // auto deref.
assert_eq!((&&()).type_size(), 8);

Returns Some(self) if it satisfies the given predicate function, or None if it doesn’t.

Examples
use aoko::no_std::functions::ext::*;

assert_eq!(Some("Hello"), "Hello".take_if(|s| s.starts_with("Hel")));
assert_eq!(None, "Hello".take_if(|s| s.starts_with("Wor")));

Returns Some(self) if it doesn’t satisfy the given predicate function, or None if it does.

Examples
use aoko::no_std::functions::ext::*;

assert_eq!(None, "Hello".take_unless(|s| s.starts_with("Hel")));
assert_eq!(Some("Hello"), "Hello".take_unless(|s| s.starts_with("Wor")));

Implementors