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]

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());
    }
}

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;
        }
    }
}

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]

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

Auto Trait Implementations

impl<'a> !Send for Raw<'a>

impl<'a> !Sync for Raw<'a>