Struct rouille::ResponseBody

source ·
pub struct ResponseBody { /* private fields */ }
Expand description

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");

Implementations§

source§

impl ResponseBody

source

pub fn empty() -> ResponseBody

Builds a ResponseBody that doesn’t return any data.

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

pub fn from_reader<R>(data: R) -> ResponseBodywhere R: Read + Send + 'static,

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));
source

pub fn from_reader_and_size<R>(data: R, size: usize) -> ResponseBodywhere R: Read + Send + 'static,

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

The caller must provide the content length. It is unspecified what will happen if the content length does not match the actual length of the data returned from the reader.

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

let body = ResponseBody::from_reader_and_size(io::stdin().take(128), 128);
source

pub fn from_data<D>(data: D) -> ResponseBodywhere D: Into<Vec<u8>>,

Builds a new ResponseBody that returns the given data.

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

pub fn from_file(file: File) -> ResponseBody

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);
source

pub fn from_string<S>(data: S) -> ResponseBodywhere S: Into<String>,

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

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

pub fn into_reader_and_size(self) -> (Box<dyn Read + Send>, Option<usize>)

Extracts the content of the response.

Returns the size of the body and the body itself. If the size is None, then it is unknown.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V