Struct rs3cache_utils::lazy::Lazy

source ·
pub struct Lazy<A: Clone, T, E> { /* private fields */ }

Implementations§

source§

impl<A: Clone, T, E> Lazy<A, T, E>

source

pub fn new(args: A, f: fn(_: A) -> Result<T, E>) -> Self

source

pub fn get(&self) -> &Result<T, E>

Methods from Deref<Target = Result<T, E>>§

1.0.0 · source

pub fn is_ok(&self) -> bool

Returns true if the result is Ok.

Examples
let x: Result<i32, &str> = Ok(-3);
assert_eq!(x.is_ok(), true);

let x: Result<i32, &str> = Err("Some error message");
assert_eq!(x.is_ok(), false);
1.0.0 · source

pub fn is_err(&self) -> bool

Returns true if the result is Err.

Examples
let x: Result<i32, &str> = Ok(-3);
assert_eq!(x.is_err(), false);

let x: Result<i32, &str> = Err("Some error message");
assert_eq!(x.is_err(), true);
1.0.0 · source

pub fn as_ref(&self) -> Result<&T, &E>

Converts from &Result<T, E> to Result<&T, &E>.

Produces a new Result, containing a reference into the original, leaving the original in place.

Examples
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.as_ref(), Ok(&2));

let x: Result<u32, &str> = Err("Error");
assert_eq!(x.as_ref(), Err(&"Error"));
1.47.0 · source

pub fn as_deref(&self) -> Result<&<T as Deref>::Target, &E>where T: Deref,

Converts from Result<T, E> (or &Result<T, E>) to Result<&<T as Deref>::Target, &E>.

Coerces the Ok variant of the original Result via Deref and returns the new Result.

Examples
let x: Result<String, u32> = Ok("hello".to_string());
let y: Result<&str, &u32> = Ok("hello");
assert_eq!(x.as_deref(), y);

let x: Result<String, u32> = Err(42);
let y: Result<&str, &u32> = Err(&42);
assert_eq!(x.as_deref(), y);
1.0.0 · source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

The iterator yields one value if the result is Result::Ok, otherwise none.

Examples
let x: Result<u32, &str> = Ok(7);
assert_eq!(x.iter().next(), Some(&7));

let x: Result<u32, &str> = Err("nothing!");
assert_eq!(x.iter().next(), None);
source

pub fn contains<U>(&self, x: &U) -> boolwhere U: PartialEq<T>,

🔬This is a nightly-only experimental API. (option_result_contains)

Returns true if the result is an Ok value containing the given value.

Examples
#![feature(option_result_contains)]

let x: Result<u32, &str> = Ok(2);
assert_eq!(x.contains(&2), true);

let x: Result<u32, &str> = Ok(3);
assert_eq!(x.contains(&2), false);

let x: Result<u32, &str> = Err("Some error message");
assert_eq!(x.contains(&2), false);
source

pub fn contains_err<F>(&self, f: &F) -> boolwhere F: PartialEq<E>,

🔬This is a nightly-only experimental API. (result_contains_err)

Returns true if the result is an Err value containing the given value.

Examples
#![feature(result_contains_err)]

let x: Result<u32, &str> = Ok(2);
assert_eq!(x.contains_err(&"Some error message"), false);

let x: Result<u32, &str> = Err("Some error message");
assert_eq!(x.contains_err(&"Some error message"), true);

let x: Result<u32, &str> = Err("Some other error message");
assert_eq!(x.contains_err(&"Some error message"), false);

Trait Implementations§

source§

impl<A: Debug + Clone, T: Debug, E: Debug> Debug for Lazy<A, T, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A: Clone, T, E> Deref for Lazy<A, T, E>

§

type Target = Result<T, E>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<A, T, E> RefUnwindSafe for Lazy<A, T, E>where A: RefUnwindSafe, E: UnwindSafe + RefUnwindSafe, T: UnwindSafe + RefUnwindSafe,

§

impl<A, T, E> Send for Lazy<A, T, E>where A: Send, E: Send, T: Send,

§

impl<A, T, E> Sync for Lazy<A, T, E>where A: Sync, E: Send + Sync, T: Send + Sync,

§

impl<A, T, E> Unpin for Lazy<A, T, E>where A: Unpin, E: Unpin, T: Unpin,

§

impl<A, T, E> UnwindSafe for Lazy<A, T, E>where A: UnwindSafe, E: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.