Skip to main content

RenderedChunks

Struct RenderedChunks 

Source
pub struct RenderedChunks<V>(/* private fields */);
Expand description

Outcome of rendering the individual chunks of a template. This is an intermediate output type that can be resolved into a variety of final output types.

Implementations§

Source§

impl<V: RenderValue> RenderedChunks<V>

Source

pub fn into_chunks(self) -> Vec<RenderedChunk<V>>

Get the inner list of chunks

Source

pub fn chunks(&self) -> &[RenderedChunk<V>]

Get the inner chunks as a slice

Source

pub fn iter(&self) -> impl Iterator<Item = &RenderedChunk<V>>

Get an iterator over references to the chunks

Source

pub fn unpack(self) -> Result<V, Self>

Unpack this output into a single value

If the output is a single dynamic chunk, unpack it into a scalar value. Otherwise, return Err(self).

Source§

impl RenderedChunks<Value>

Source

pub fn try_into_value(self) -> Result<Value, RenderError>

Collect the rendered chunks into a Value by these rules:

  • If the template is a single dynamic chunk, return the output of that chunk, which may be any type of Value
  • Any other template will be rendered to a string by stringifying each dynamic chunk and concatenating them all together
  • If rendering to a string fails because the bytes are not valid UTF-8, concatenate into a bytes object instead
Source

pub fn try_into_bytes(self) -> Result<Bytes, RenderError>

Collect the rendered chunks into a byte string

If any chunk is an error, return an error.

Source§

impl RenderedChunks<ValueStream>

Source

pub fn stream_source(&self) -> Option<&StreamSource>

If this output is a single chunk and that chunk is a stream, get the source of the stream

Source

pub fn has_stream(&self) -> bool

Does this output contain any stream chunks?

Source

pub async fn try_collect_value(self) -> Result<Value, RenderError>

Collect the rendered chunks into a Value by these rules:

  • If the template is a single dynamic chunk, return the output of that chunk, which may be any type of Value
  • If there are any streams, resolve them to bytes
  • Any other template will be rendered to a string by stringifying each dynamic chunk and concatenating them all together
  • If rendering to a string fails because the bytes are not valid UTF-8, concatenate into a bytes object instead
Source

pub fn try_into_stream( self, ) -> Result<impl Stream<Item = Result<Bytes, RenderError>> + Send, RenderError>

Convert this output into a byte stream. Each chunk will be yielded as a separate Bytes output from the stream, except for inner stream chunks, which can yield any number of values based on their implementation. Return Err if any of the rendered chunks are errors.

Trait Implementations§

Source§

impl<V: Debug> Debug for RenderedChunks<V>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<V: From<Value>> From<Result<Value, RenderError>> for RenderedChunks<V>

Create render output of a single chunk that may have failed

Source§

fn from(result: Result<Value, RenderError>) -> Self

Converts to this type from the input type.
Source§

impl<V: From<Value>> From<Value> for RenderedChunks<V>

Create render output of a single chunk with a value

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl<'a, V> IntoIterator for &'a RenderedChunks<V>

Get an iterator over references to chunks of this output

Source§

type Item = &'a RenderedChunk<V>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, RenderedChunk<V>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<V> IntoIterator for RenderedChunks<V>

Get an iterator over the chunks of this output

Source§

type Item = RenderedChunk<V>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<RenderedChunks<V> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<V> Freeze for RenderedChunks<V>

§

impl<V> !RefUnwindSafe for RenderedChunks<V>

§

impl<V> Send for RenderedChunks<V>
where V: Send,

§

impl<V> Sync for RenderedChunks<V>
where V: Sync,

§

impl<V> Unpin for RenderedChunks<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for RenderedChunks<V>

§

impl<V> !UnwindSafe for RenderedChunks<V>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more