Struct rouille::ResponseBody [] [src]

pub struct ResponseBody { /* fields omitted */ }

An opaque type that represents the body of a response.

You can't access the inside of this struct, but you can build one by using one of the provided constructors.

Example

use rouille::ResponseBody;
let body = ResponseBody::from_string("hello world");

Methods

impl ResponseBody
[src]

Builds a ResponseBody that doesn't return any data.

Example

use rouille::ResponseBody;
let body = ResponseBody::empty();

Builds a new ResponseBody that will read the data from a Read.

Note that this is suboptimal compared to other constructors because the length isn't known in advance.

Example

use std::io;
use std::io::Read;
use rouille::ResponseBody;

let body = ResponseBody::from_reader(io::stdin().take(128));

Builds a new ResponseBody that returns the given data.

Example

use rouille::ResponseBody;
let body = ResponseBody::from_data(vec![12u8, 97, 34]);

Builds a new ResponseBody that returns the content of the given file.

Example

use std::fs::File;
use rouille::ResponseBody;

let file = File::open("page.html").unwrap();
let body = ResponseBody::from_file(file);

Builds a new ResponseBody that returns an UTF-8 string.

Example

use rouille::ResponseBody;
let body = ResponseBody::from_string("hello world");