Skip to main content

CallableWith

Trait CallableWith 

Source
pub trait CallableWith<T, R, E> {
    // Required method
    fn call_with(&mut self, input: &mut T) -> Result<R, E>;

    // Provided methods
    fn into_box(self) -> BoxCallableWith<T, R, E>
       where Self: Sized + 'static { ... }
    fn into_rc(self) -> RcCallableWith<T, R, E>
       where Self: Sized + 'static { ... }
    fn into_arc(self) -> ArcCallableWith<T, R, E>
       where Self: Sized + Send + 'static { ... }
    fn into_fn(self) -> impl FnMut(&mut T) -> Result<R, E>
       where Self: Sized + 'static { ... }
    fn to_box(&self) -> BoxCallableWith<T, R, E>
       where Self: Clone + Sized + 'static { ... }
    fn to_rc(&self) -> RcCallableWith<T, R, E>
       where Self: Clone + Sized + 'static { ... }
    fn to_arc(&self) -> ArcCallableWith<T, R, E>
       where Self: Clone + Send + Sized + 'static { ... }
    fn to_fn(&self) -> impl FnMut(&mut T) -> Result<R, E>
       where Self: Clone + Sized + 'static { ... }
    fn into_runnable_with(self) -> BoxRunnableWith<T, E>
       where Self: Sized + 'static { ... }
}
Expand description

A fallible, reusable computation that receives mutable input.

Conceptually this is FnMut(&mut T) -> Result<R, E> with task-oriented naming. It is useful for executor-style APIs that run a task with access to protected state, such as a value held under a lock.

§Type Parameters

  • T - The mutable input type.
  • R - The success value returned by the computation.
  • E - The error value returned when the computation fails.

§Author

Haixing Hu

Required Methods§

Source

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

Executes the computation with mutable input.

§Parameters
  • input - The mutable input passed to this task.
§Returns

Returns Ok(R) when the computation succeeds, or Err(E) when it fails. The exact error meaning is defined by the concrete callable.

Provided Methods§

Source

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

Converts this callable into a boxed callable.

§Returns

A BoxCallableWith<T, R, E>.

Source

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

Converts this callable into an Rc callable.

§Returns

A RcCallableWith<T, R, E>.

Source

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

Converts this callable into an Arc callable.

§Returns

An ArcCallableWith<T, R, E>.

Source

fn into_fn(self) -> impl FnMut(&mut T) -> Result<R, E>
where Self: Sized + 'static,

Converts this callable into a mutable closure.

§Returns

A closure implementing FnMut(&mut T) -> Result<R, E>.

Source

fn to_box(&self) -> BoxCallableWith<T, R, E>
where Self: Clone + Sized + 'static,

Converts this callable into a boxed callable without consuming self.

§Returns

A BoxCallableWith<T, R, E> built from a clone of this callable.

Source

fn to_rc(&self) -> RcCallableWith<T, R, E>
where Self: Clone + Sized + 'static,

Converts this callable into an Rc callable without consuming self.

§Returns

A RcCallableWith<T, R, E> built from a clone of this callable.

Source

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

Converts this callable into an Arc callable without consuming self.

§Returns

An ArcCallableWith<T, R, E> built from a clone of this callable.

Source

fn to_fn(&self) -> impl FnMut(&mut T) -> Result<R, E>
where Self: Clone + Sized + 'static,

Converts this callable into a mutable closure without consuming self.

§Returns

A closure implementing FnMut(&mut T) -> Result<R, E>.

Source

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

Converts this callable into a runnable by discarding the success value.

§Returns

A BoxRunnableWith<T, E> preserving errors and mapping success to unit.

Implementors§

Source§

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

Source§

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

Source§

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

Source§

impl<T, R, E, F> CallableWith<T, R, E> for F
where F: FnMut(&mut T) -> Result<R, E>,