pub struct Answer { /* private fields */ }Expand description
Answers calls from a closure, for a dry run.
The closure is asked about each call it wraps, and sees the call’s
Ctx: its info, its input, resolved with
every secret-reading field null, and the
primary_output an answer is written through.
Some(value) is written with Ctx::emit_default, through the callee’s
primary output, and the call returns Outcome::Ok without reaching the
layers inside this one or the function. None passes the call on. A
callee with no primary output fails the call with a Config error.
use dataflow_rs::datavalue::OwnedDataValue;
use dataflow_rs::function::{CallLayer, layers::Answer};
use dataflow_rs::RunOptions;
use std::sync::Arc;
// Every `http_call` that has somewhere to write answers with the input
// it was given; the rest run.
let dry_run: Vec<Arc<dyn CallLayer>> = vec![Arc::new(Answer::new(|ctx| {
if ctx.info().function != "http_call" || ctx.primary_output().is_none() {
return None;
}
let input = ctx.input().ok()?;
Some(OwnedDataValue::Object(vec![
("status".into(), "dry run".into()),
("request".into(), input),
]))
}))];
let opts = RunOptions::default().layers(&dry_run);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Answer
impl !UnwindSafe for Answer
impl Freeze for Answer
impl Send for Answer
impl Sync for Answer
impl Unpin for Answer
impl UnsafeUnpin for Answer
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