Struct rustful::response::Chunked [] [src]

pub struct Chunked<'a, 'b> { /* fields omitted */ }

An interface for writing a chunked response body.

This is useful for when the size of the data is unknown, but it comes with an overhead for each time send or try_send is called (simply put).

Methods

impl<'a, 'b> Chunked<'a, 'b>
[src]

Get a reference to the filter storage.

Get a mutable reference to the filter storage. It can be used to communicate with the response filters.

Send a chunk of data to the client, ignoring any eventual errors. Use try_send to get error information.

use rustful::{Context, Response};

fn my_handler(context: Context, response: Response) {
    let count = context.variables.get("count")
        .and_then(|n| n.parse().ok())
        .unwrap_or(0u32);
    let mut chunked = response.into_chunked();

    for i in 0..count {
        chunked.send(format!("chunk #{}", i + 1));
    }
}

Send a chunk of data to the client. This is the same as send, but errors are not ignored.

#[macro_use] extern crate log;
use rustful::{Context, Response};
use rustful::response::Error;

fn my_handler(context: Context, response: Response) {
    let count = context.variables.get("count")
        .and_then(|n| n.parse().ok())
        .unwrap_or(0u32);
    let mut chunked = response.into_chunked();

    for i in 0..count {
        if let Err(Error::Filter(e)) = chunked.try_send(format!("chunk #{}", i + 1)) {
            error!("a filter failed: {}", e);
        }
    }
}

Finish writing the response and collect eventual errors.

This is optional and will happen silently when the writer drops out of scope.

Trait Implementations

impl<'a, 'b> Write for Chunked<'a, 'b>
[src]

Write a buffer into this object, returning how many bytes were written. Read more

Attempts to write an entire buffer into this write. Read more

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Important traits for &'a mut R

Creates a "by reference" adaptor for this instance of Write. Read more

impl<'a, 'b> Drop for Chunked<'a, 'b>
[src]

Finishes writing and closes the connection.

Auto Trait Implementations

impl<'a, 'b> !Send for Chunked<'a, 'b>

impl<'a, 'b> !Sync for Chunked<'a, 'b>