Skip to main content

StreamRestorer

Struct StreamRestorer 

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

Restores one block of streamed model text.

Text is released as soon as it cannot be part of a placeholder. A tail that could still become one (for the default format, an open [ followed only by placeholder characters) is held until it completes, stops matching, grows past the longest possible placeholder, or StreamRestorer::finish is called.

It holds no reference to the engine, so it can live inside a long-running response stream; the engine and scope are passed to each call.

Implementations§

Source§

impl StreamRestorer

Source

pub fn push(&mut self, engine: &Engine, scope: &ScopeId, chunk: &str) -> String

Adds a chunk and returns the restored text that is safe to send now.

Source

pub fn finish(&mut self, engine: &Engine, scope: &ScopeId) -> String

Flushes any held text at the end of the block.

Source

pub fn is_holding(&self) -> bool

True while text is being held back.

Source

pub fn report(&self) -> &Report

Counts so far for this block.

Trait Implementations§

Source§

impl Default for StreamRestorer

Source§

fn default() -> Self

Returns the “default value” for a type. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.