pub struct PipelineBuilder<T: Clone + Send + Sync + 'static> { /* private fields */ }Expand description
PipelineBuilder provides flexibility and extensibility to your pipelines
Pipes/function can be appended to your type pipeline from other places in your code or even across crates.
#[derive(Default, Clone)]
struct MeaningOfLife(i32);
#[tokio::main]
async fn main() {
let builder = PipelineBuilder::<MeaningOfLife>::new();
builder.register(|pipeline| {
Box::pin(async {
pipeline.store_fn(|mut instance: MeaningOfLife| async {
instance.0 = 42;
instance
}).await
})
}).await;
let life = builder.build(MeaningOfLife::default()).await.deliver().await;
assert_eq!(life.0, 42);
}
You can implement the PipelineBuilderTrait for your type as well
#[derive(Default, Clone)]
struct MeaningOfLife(i32);
#[fama::async_trait]
impl PipelineBuilderTrait for MeaningOfLife {
// we are overriding the default implementation of this method in order
// to append our pipe
async fn setup_pipeline_builder(builder: PipelineBuilder<Self>) -> PipelineBuilder<Self> {
builder.register(|pipeline| {
Box::pin(async {
pipeline.store_fn(|mut instance: MeaningOfLife| async {
instance.0 = 42;
instance
}).await
})
}).await;
builder
}
}
#[tokio::main]
async fn main() {
let new_life = MeaningOfLife(0);
// Register/append a pipe/function to the pipeline
MeaningOfLife::pipeline_builder().await
.register(|pipeline| {
Box::pin(async {
pipeline.store_fn(|mut instance: MeaningOfLife| async {
if instance.0 == 0 {
instance.0 = 42 ;
} else {
instance.0 = instance.0 * 2;
}
instance
}).await
})
}).await;
let life = new_life.pipeline().await.deliver().await;
assert_eq!(life.0, 84);
}
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for PipelineBuilder<T>
impl<T> !RefUnwindSafe for PipelineBuilder<T>
impl<T> Send for PipelineBuilder<T>
impl<T> Sync for PipelineBuilder<T>
impl<T> Unpin for PipelineBuilder<T>
impl<T> !UnwindSafe for PipelineBuilder<T>
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