Skip to main content

ResponseAssembler

Struct ResponseAssembler 

Source
pub struct ResponseAssembler { /* private fields */ }
Expand description

Turns raw run events into ordered response text. See the module docs.

Implementations§

Source§

impl ResponseAssembler

Source

pub fn new(graph: &Arc<Graph>) -> Self

Build an assembler for runs of graph.

Source

pub fn pass_through_unreferenced(self, enabled: bool) -> Self

Forward chunks that no template references (and child-frame chunks) verbatim.

Source

pub fn include_end(self, enabled: bool) -> Self

Also render end nodes (their outputs joined by newlines).

Source

pub fn with_value(self, selector: &Selector, value: Value) -> Self

Provide a value for a non-node variable such as sys.query.

Source

pub fn with_pool(self, pool: VariablePool) -> Self

Provide non-node variables in bulk (e.g. the run’s sys / conversation values).

Source

pub fn resume_from(self, snapshot: &FrameSnapshot) -> Self

Continue assembling a resumed run from the root frame snapshot carried by RunPaused (snapshot.root).

Restores every variable value of the snapshot (node outputs included, so templates can reference nodes that will not run again), node and edge states (for correct ordering), and marks response nodes that already succeeded before the pause as rendered, so they are not emitted twice. A response that was only partially rendered when the run paused is rendered again from the start.

Source

pub fn text_so_far(&self) -> &str

All response text emitted so far, concatenated.

Source

pub fn push(&mut self, event: &Event) -> Vec<ResponseChunk>

Feed one event; returns the response chunks it unlocks.

Source

pub fn push_into(&mut self, event: &Event, out: &mut Vec<ResponseChunk>)

ResponseAssembler::push appending to out instead of returning a new list, so a consumer can reuse one buffer for a whole run.

let mut assembler = ResponseAssembler::new(&graph);
let mut chunks = Vec::new();
for event in &events {
    assembler.push_into(event, &mut chunks);
    for chunk in chunks.drain(..) {
        print!("{}", chunk.text);
    }
}
Source

pub fn finish(&mut self) -> Vec<ResponseChunk>

Flush: treat every pending variable as resolved and render what is available. Idempotent.

Trait Implementations§

Source§

impl Debug for ResponseAssembler

Source§

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

Formats the value using the given formatter. Read more

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.