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>
impl<I> Context<I>
Sourcepub fn new(input: I, shared: Shared) -> Self
pub fn new(input: I, shared: Shared) -> Self
Creates a new context with the provided input and shared dependency collection.
pub fn empty(input: I) -> Self
Sourcepub async fn invoke<H, Args, O>(self, handler: H) -> Context<O>
pub async fn invoke<H, Args, O>(self, handler: H) -> Context<O>
§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§
Auto Trait Implementations§
impl<Input> Freeze for Context<Input>where
Input: ?Sized,
impl<Input> !RefUnwindSafe for Context<Input>
impl<Input> Send for Context<Input>
impl<Input> Sync for Context<Input>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more