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]
impl<'a, 'b> Chunked<'a, 'b>
pub fn filter_storage(&self) -> &AnyMap
[src]
pub fn filter_storage(&self) -> &AnyMap
Get a reference to the filter storage.
pub fn filter_storage_mut(&mut self) -> &mut AnyMap
[src]
pub fn filter_storage_mut(&mut self) -> &mut AnyMap
Get a mutable reference to the filter storage. It can be used to communicate with the response filters.
pub fn send<'d, Content: Into<Data<'d>>>(&mut self, content: Content)
[src]
pub fn send<'d, Content: Into<Data<'d>>>(&mut self, content: Content)
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)); } }
pub fn try_send<'d, Content: Into<Data<'d>>>(
&mut self,
content: Content
) -> Result<usize, Error>
[src]
pub fn try_send<'d, Content: Into<Data<'d>>>(
&mut self,
content: Content
) -> Result<usize, Error>
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); } } }
pub fn end(self) -> Result<(), Error>
[src]
pub fn end(self) -> Result<(), Error>
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]
impl<'a, 'b> Write for Chunked<'a, 'b>
fn write(&mut self, content: &[u8]) -> Result<usize>
[src]
fn write(&mut self, content: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written. Read more
fn write_all(&mut self, content: &[u8]) -> Result<()>
[src]
fn write_all(&mut self, content: &[u8]) -> Result<()>
Attempts to write an entire buffer into this write. Read more
fn flush(&mut self) -> Result<()>
[src]
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
Writes a formatted string into this writer, returning any error encountered. Read more
ⓘImportant traits for &'a mut Rfn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Write
. Read more
impl<'a, 'b> Drop for Chunked<'a, 'b>
[src]
impl<'a, 'b> Drop for Chunked<'a, 'b>