Skip to main content

BoxCallableOnce

Struct BoxCallableOnce 

Source
pub struct BoxCallableOnce<R, E> { /* private fields */ }
Expand description

Box-based one-time callable.

BoxCallableOnce<R, E> stores a Box<dyn FnOnce() -> Result<R, E>> and can be executed only once. It is the boxed concrete implementation of CallableOnce.

§Type Parameters

  • R - The success value returned by the computation.
  • E - The error value returned when the computation fails.

§Examples

use qubit_function::{BoxCallableOnce, CallableOnce};

let task = BoxCallableOnce::new(|| Ok::<i32, String>(42));
assert_eq!(task.call(), Ok(42));

§Author

Haixing Hu

Implementations§

Source§

impl<R, E> BoxCallableOnce<R, E>

Source

pub fn new<F>(function: F) -> Self
where F: FnOnce() -> Result<R, E> + 'static,

Creates a new callable.

Wraps the provided closure in the appropriate smart pointer type for this callable implementation.

Source

pub fn new_with_name<F>(name: &str, function: F) -> Self
where F: FnOnce() -> Result<R, E> + 'static,

Creates a new named callable.

Wraps the provided closure and assigns it a name, which is useful for debugging and logging purposes.

Source

pub fn new_with_optional_name<F>(function: F, name: Option<String>) -> Self
where F: FnOnce() -> Result<R, E> + 'static,

Creates a new named callable with an optional name.

Wraps the provided closure and assigns it an optional name.

Source

pub fn from_supplier<S>(supplier: S) -> Self
where S: SupplierOnce<Result<R, E>> + 'static,

Creates a boxed callable from a one-time supplier.

This is an explicit bridge from SupplierOnce<Result<R, E>> to CallableOnce<R, E>.

§Parameters
  • supplier - The supplier that produces the callable result.
§Returns

A new BoxCallableOnce<R, E>.

Source

pub fn name(&self) -> Option<&str>

Gets the name of this callable.

§Returns

Returns Some(&str) if a name was set, None otherwise.

Source

pub fn set_name(&mut self, name: &str)

Sets the name of this callable.

§Parameters
  • name - The name to set for this callable
Source

pub fn clear_name(&mut self)

Clears the name of this callable.

Source

pub fn map<U, M>(self, mapper: M) -> BoxCallableOnce<U, E>
where M: FnOnce(R) -> U + 'static, R: 'static, E: 'static,

Maps the success value of this callable.

§Parameters
  • mapper - Function that transforms the success value.
§Returns

A new callable that applies mapper when this callable succeeds.

Source

pub fn map_err<E2, M>(self, mapper: M) -> BoxCallableOnce<R, E2>
where M: FnOnce(E) -> E2 + 'static, R: 'static, E: 'static,

Maps the error value of this callable.

§Parameters
  • mapper - Function that transforms the error value.
§Returns

A new callable that applies mapper when this callable fails.

Source

pub fn and_then<U, N>(self, next: N) -> BoxCallableOnce<U, E>
where N: FnOnce(R) -> Result<U, E> + 'static, R: 'static, E: 'static,

Chains another fallible computation after this callable succeeds.

§Parameters
  • next - Function that receives the success value and returns the next result.
§Returns

A new callable that runs next only when this callable succeeds.

Trait Implementations§

Source§

impl<R, E> CallableOnce<R, E> for BoxCallableOnce<R, E>

Source§

fn call(self) -> Result<R, E>

Executes the boxed callable.

Source§

fn into_runnable(self) -> BoxRunnableOnce<E>
where Self: Sized + 'static,

Converts this boxed callable into a boxed runnable while preserving its name.

Source§

fn into_box(self) -> BoxCallableOnce<R, E>

Converts this callable into a boxed callable. Read more
Source§

fn into_fn(self) -> impl FnOnce() -> Result<R, E>

Converts this callable into a closure. Read more
Source§

impl<R, E> Debug for BoxCallableOnce<R, E>

Source§

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

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

impl<R, E> Display for BoxCallableOnce<R, E>

Source§

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

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

impl<R, E> SupplierOnce<Result<R, E>> for BoxCallableOnce<R, E>

Source§

fn get(self) -> Result<R, E>

Executes the boxed callable as a one-time supplier of Result<R, E>.

Source§

fn into_box(self) -> BoxSupplierOnce<T>
where Self: Sized + 'static,

Converts to BoxSupplierOnce. Read more
Source§

fn into_fn(self) -> impl FnOnce() -> T
where Self: Sized + 'static,

Converts the supplier to a Box<dyn FnOnce() -> T>. Read more

Auto Trait Implementations§

§

impl<R, E> Freeze for BoxCallableOnce<R, E>

§

impl<R, E> !RefUnwindSafe for BoxCallableOnce<R, E>

§

impl<R, E> !Send for BoxCallableOnce<R, E>

§

impl<R, E> !Sync for BoxCallableOnce<R, E>

§

impl<R, E> Unpin for BoxCallableOnce<R, E>

§

impl<R, E> UnsafeUnpin for BoxCallableOnce<R, E>

§

impl<R, E> !UnwindSafe for BoxCallableOnce<R, E>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.