Skip to main content

BoxCallableWith

Struct BoxCallableWith 

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

Box-based callable with mutable input.

BoxCallableWith<T, R, E> stores a Box<dyn FnMut(&mut T) -> Result<R, E>> and can be called repeatedly.

§Author

Haixing Hu

Implementations§

Source§

impl<T, R, E> BoxCallableWith<T, R, E>

Source

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

Creates a new callable-with.

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

Source

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

Creates a new named callable-with.

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: FnMut(&mut T) -> Result<R, E> + 'static,

Creates a new named callable-with with an optional name.

Wraps the provided closure and assigns it an optional name.

Source

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

Gets the name of this callable-with.

§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-with.

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

pub fn clear_name(&mut self)

Clears the name of this callable-with.

Source

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

Maps the success value of this callable.

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

A new callable with mutable input that applies mapper on success.

Source

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

Maps the error value of this callable.

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

A new callable with mutable input that applies mapper on failure.

Source

pub fn and_then<U, N>(self, next: N) -> BoxCallableWith<T, U, E>
where N: FnMut(R, &mut T) -> Result<U, E> + 'static, T: 'static, R: 'static, E: 'static,

Chains another fallible computation after this callable succeeds.

§Parameters
  • next - Function receiving the success value and mutable input.
§Returns

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

Trait Implementations§

Source§

impl<T, R, E> CallableWith<T, R, E> for BoxCallableWith<T, R, E>

Source§

fn call_with(&mut self, input: &mut T) -> Result<R, E>

Executes the boxed callable with mutable input.

Source§

fn into_runnable_with(self) -> BoxRunnableWith<T, E>
where Self: Sized + 'static,

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

Source§

fn into_box(self) -> BoxCallableWith<T, R, E>

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

fn into_rc(self) -> RcCallableWith<T, R, E>
where Self: 'static,

Converts this callable into an Rc callable. Read more
Source§

fn into_fn(self) -> impl FnMut(&mut T) -> Result<R, E>

Converts this callable into a mutable closure. Read more
Source§

fn into_arc(self) -> ArcCallableWith<T, R, E>
where Self: Sized + Send + 'static,

Converts this callable into an Arc callable. Read more
Source§

impl<T, R, E> Debug for BoxCallableWith<T, R, E>

Source§

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

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

impl<T, R, E> Display for BoxCallableWith<T, R, E>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, R, E> Freeze for BoxCallableWith<T, R, E>

§

impl<T, R, E> !RefUnwindSafe for BoxCallableWith<T, R, E>

§

impl<T, R, E> !Send for BoxCallableWith<T, R, E>

§

impl<T, R, E> !Sync for BoxCallableWith<T, R, E>

§

impl<T, R, E> Unpin for BoxCallableWith<T, R, E>

§

impl<T, R, E> UnsafeUnpin for BoxCallableWith<T, R, E>

§

impl<T, R, E> !UnwindSafe for BoxCallableWith<T, 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.