Skip to main content

Context

Struct Context 

Source
pub struct Context<Input>
where Input: ?Sized,
{ /* private fields */ }
Expand description

The execution context for a pipeline, carrying both shared dependencies and the specific input.

Implementations§

Source§

impl<I> Context<I>

Source

pub fn new(input: I, shared: Shared) -> Self

Creates a new context with the provided input and shared dependency collection.

Source

pub fn empty(input: I) -> Self

Source

pub async fn invoke<H, Args, O>(self, handler: H) -> Context<O>
where H: Handler<I, O, Args>, I: Clone + Send + Sync + 'static, O: Send + Sync + 'static, Args: Send + Sync + 'static,

§Example
use pipe_it::{Context, Input, Res, ResMut, Shared};

#[derive(Debug, Clone)]
struct Counter {
    c: i32,
}

#[tokio::main]
async fn main() {
    let ctx = Context::new(3, Shared::new().insert(Counter { c: 1 }));
    ctx.invoke(async |x: Input<i32>, mut counter: ResMut<Counter>| {
        counter.c += 1;
        *x + 1
    })
    .await
    .invoke(async |x: Input<i32>, counter: Res<Counter>| *x + counter.c)
    .await
    .invoke(async |x: Input<i32>| assert_eq!(*x, 6))
    .await;
}

Trait Implementations§

Source§

impl<Input> Clone for Context<Input>
where Input: ?Sized,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Input> Freeze for Context<Input>
where Input: ?Sized,

§

impl<Input> !RefUnwindSafe for Context<Input>

§

impl<Input> Send for Context<Input>
where Input: Sync + Send + ?Sized,

§

impl<Input> Sync for Context<Input>
where Input: Sync + Send + ?Sized,

§

impl<Input> Unpin for Context<Input>
where Input: ?Sized,

§

impl<Input> UnsafeUnpin for Context<Input>
where Input: ?Sized,

§

impl<Input> !UnwindSafe for Context<Input>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.