Struct rustful::response::Raw
[−]
[src]
pub struct Raw<'a> { /* fields omitted */ }
A streaming fixed-size response.
Everything is written directly to the network stream, without being
filtered, which makes Raw
especially suitable for transferring files.
Unsafety: The content length is set beforehand, which makes it possible to send responses that are too short.
Methods
impl<'a> Raw<'a>
[src]
impl<'a> Raw<'a>
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 piece 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(0u8); let mut raw = unsafe { response.into_raw(count as u64) }; for i in 0..count { raw.send([i].as_ref()); } }
pub fn try_send<'d, Content: Into<Data<'d>>>(
&mut self,
content: Content
) -> Result<()>
[src]
pub fn try_send<'d, Content: Into<Data<'d>>>(
&mut self,
content: Content
) -> Result<()>
Send a piece 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}; fn my_handler(context: Context, response: Response) { let count = context.variables.get("count") .and_then(|n| n.parse().ok()) .unwrap_or(0u8); let mut raw = unsafe { response.into_raw(count as u64) }; for i in 0..count { if let Err(e) = raw.try_send([i].as_ref()) { error!("failed to write: {}", e); break; } } }
pub fn end(self) -> Result<()>
[src]
pub fn end(self) -> Result<()>
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> Write for Raw<'a>
[src]
impl<'a> Write for Raw<'a>
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