Struct rocket::response::stream::TextStream[][src]

pub struct TextStream<S>(pub S);
Expand description

A potentially infinite stream of text: T: AsRef<str>.

A TextStream can be constructed from any Stream of items of type T where T: AsRef<str>. This includes &str, String, Cow<str>, &RawStr, and more. The stream can be constructed directly, via TextStream(..) or TextStream::from(), or through generator syntax via TextStream!.

Responder

TextStream is a (potentially infinite) responder. The response Content-Type is set to Text. The body is unsized, and values are sent as soon as they are yielded by the internal iterator.

Example

Use TextStream! to yield 10 strings, one every second, of the form "n: $k" for $k from 0 to 10 exclusive:

use rocket::response::stream::TextStream;
use rocket::futures::stream::{repeat, StreamExt};
use rocket::tokio::time::{self, Duration};

#[get("/text")]
fn text() -> TextStream![&'static str] {
    TextStream(repeat("hi"))
}

#[get("/text/stream")]
fn stream() -> TextStream![String] {
    TextStream! {
        let mut interval = time::interval(Duration::from_secs(1));
        for i in 0..10 {
            yield format!("n: {}", i);
            interval.tick().await;
        }
    }
}

The syntax of TextStream! as an expression is identical to that of stream!.

Trait Implementations

impl<S: Clone> Clone for TextStream<S>[src]

fn clone(&self) -> TextStream<S>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<S: Debug> Debug for TextStream<S>[src]

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

Formats the value using the given formatter. Read more

impl<S> From<S> for TextStream<S>[src]

fn from(stream: S) -> Self[src]

Creates a TextStream from any S: Stream.

impl<'r, S: Stream> Responder<'r, 'r> for TextStream<S> where
    S: Send + 'r,
    S::Item: AsRef<str> + Send + Unpin + 'r, 
[src]

fn respond_to(self, _: &'r Request<'_>) -> Result<'r>[src]

Returns Ok if a Response could be generated successfully. Otherwise, returns an Err with a failing Status. Read more

Auto Trait Implementations

impl<S> RefUnwindSafe for TextStream<S> where
    S: RefUnwindSafe

impl<S> Send for TextStream<S> where
    S: Send

impl<S> Sync for TextStream<S> where
    S: Sync

impl<S> Unpin for TextStream<S> where
    S: Unpin

impl<S> UnwindSafe for TextStream<S> where
    S: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<!> for T[src]

pub fn from(t: !) -> T[src]

Performs the conversion.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

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

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

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> IntoCollection<T> for T

pub fn into_collection<A>(self) -> SmallVec<A> where
    A: Array<Item = T>, 

Converts self into a collection.

pub fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
    F: FnMut(T) -> U,
    A: Array<Item = U>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V