Skip to main content

RunnablePick

Trait RunnablePick 

Source
pub trait RunnablePick<I: Send + Sync + 'static>: Sized {
    // Required methods
    fn pick<K>(
        self,
        keys: impl IntoIterator<Item = K>,
    ) -> RunnableSequence<I, HashMap<String, Value>>
       where K: Into<String>;
    fn pluck(self, key: impl Into<String>) -> RunnableSequence<I, Value>;
}
Expand description

Extracts keys / values from a Runnable whose output is a HashMap<String, Value>.

Required Methods§

Source

fn pick<K>( self, keys: impl IntoIterator<Item = K>, ) -> RunnableSequence<I, HashMap<String, Value>>
where K: Into<String>,

Keep only the given keys of the dict output, dropping everything else.

Missing keys are omitted from the result (Python raises KeyError; Rust’s map semantics make omission the closest safe equivalent).

§Example
let parallel = RunnableParallel::<String>::new()
    .with("a", RunnableLambda::new_sync(|s: String| s.len() as i64))
    .with("b", RunnableLambda::new_sync(|s: String| s.to_uppercase()));
let picked = parallel.pick(["a"]);   // output: {"a": N}
Source

fn pluck(self, key: impl Into<String>) -> RunnableSequence<I, Value>

Pull a single value out of the dict output.

A missing key yields Value::Null (Python raises KeyError; Null keeps the runnable total so the pipeline does not short-circuit).

§Example
let val = parallel.pluck("a");   // output: Value

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<I, R> RunnablePick<I> for R
where I: Send + Sync + 'static, R: Runnable<I, HashMap<String, Value>> + Sized + 'static, R::Error: Into<LcelError>,