Skip to main content

FnTask

Struct FnTask 

Source
pub struct FnTask<F, I, O, Fut>(/* private fields */);
Expand description

Wrapper that enables closures to implement CoreTask.

Use the fn_task helper function to create instances with inferred types.

§Example

use sayiir_core::task::fn_task;

// Both work with the same `register` method:
registry.register("closure", codec.clone(), fn_task(|i: u32| async move { Ok(i * 2) }));
registry.register("struct", codec.clone(), MyTask::new());

Trait Implementations§

Source§

impl<F, I, O, Fut> CoreTask for FnTask<F, I, O, Fut>
where F: Fn(I) -> Fut + Send + Sync, I: Send, O: Send, Fut: Future<Output = Result<O, BoxError>> + Send,

Source§

type Input = I

Source§

type Output = O

Source§

type Future = Fut

Source§

fn run(&self, input: I) -> Self::Future

Run the task with the given input and return the output.

Auto Trait Implementations§

§

impl<F, I, O, Fut> Freeze for FnTask<F, I, O, Fut>
where F: Freeze,

§

impl<F, I, O, Fut> RefUnwindSafe for FnTask<F, I, O, Fut>
where F: RefUnwindSafe,

§

impl<F, I, O, Fut> Send for FnTask<F, I, O, Fut>
where F: Send,

§

impl<F, I, O, Fut> Sync for FnTask<F, I, O, Fut>
where F: Sync,

§

impl<F, I, O, Fut> Unpin for FnTask<F, I, O, Fut>
where F: Unpin,

§

impl<F, I, O, Fut> UnsafeUnpin for FnTask<F, I, O, Fut>
where F: UnsafeUnpin,

§

impl<F, I, O, Fut> UnwindSafe for FnTask<F, I, O, Fut>
where F: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.