Skip to main content

Answer

Struct Answer 

Source
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§

Source§

impl Answer

Source

pub fn new( f: impl Fn(&Ctx<'_>) -> Option<OwnedDataValue> + Send + Sync + 'static, ) -> Self

A layer answering each call f gives a value for.

Trait Implementations§

Source§

impl CallLayer for Answer

Source§

fn call<'a>( &'a self, ctx: &'a mut Ctx<'_>, next: Next<'a>, ) -> BoxFuture<'a, Result<Outcome>>

Wraps one call. next is the rest of the chain.
Source§

impl Debug for Answer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Nothing of the closure.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.