Trait viz_core::ResponseExt
source · pub trait ResponseExt: Sized {
Show 13 methods
// Required methods
fn content_length(&self) -> Option<u64>;
fn ok(&self) -> bool;
fn location(location: &'static str) -> Self;
fn redirect<T>(url: T) -> Response
where T: AsRef<str>;
fn redirect_with_status<T>(uri: T, status: StatusCode) -> Response
where T: AsRef<str>;
// Provided methods
fn with<T>(t: T, c: &'static str) -> Response
where T: Into<Body> { ... }
fn text<T>(t: T) -> Response
where T: Into<Body> { ... }
fn html<T>(t: T) -> Response
where T: Into<Body> { ... }
fn json<T>(t: T) -> Result<Response, PayloadError>
where T: Serialize { ... }
fn stream<S, O, E>(s: S) -> Response
where S: Stream<Item = Result<O, E>> + Send + 'static,
O: Into<Bytes> + 'static,
E: Error + Send + Sync + 'static { ... }
fn see_other<T>(url: T) -> Response
where T: AsRef<str> { ... }
fn temporary<T>(url: T) -> Response
where T: AsRef<str> { ... }
fn permanent<T>(url: T) -> Response
where T: AsRef<str> { ... }
}
Expand description
The Response Extension.
Required Methods§
sourcefn content_length(&self) -> Option<u64>
fn content_length(&self) -> Option<u64>
Get the size of this response’s body.
sourcefn location(location: &'static str) -> Self
fn location(location: &'static str) -> Self
The Content-Location
header indicates an alternate location for the returned data.
sourcefn redirect<T>(url: T) -> Responsewhere
T: AsRef<str>,
fn redirect<T>(url: T) -> Responsewhere T: AsRef<str>,
The response redirects to the specified URL.
sourcefn redirect_with_status<T>(uri: T, status: StatusCode) -> Responsewhere
T: AsRef<str>,
fn redirect_with_status<T>(uri: T, status: StatusCode) -> Responsewhere T: AsRef<str>,
The response redirects to the specified URL and the status code.
Provided Methods§
sourcefn with<T>(t: T, c: &'static str) -> Responsewhere
T: Into<Body>,
fn with<T>(t: T, c: &'static str) -> Responsewhere T: Into<Body>,
The response with the specified Content-Type
.
sourcefn text<T>(t: T) -> Responsewhere
T: Into<Body>,
fn text<T>(t: T) -> Responsewhere T: Into<Body>,
The response with text/plain; charset=utf-8
media type.
sourcefn html<T>(t: T) -> Responsewhere
T: Into<Body>,
fn html<T>(t: T) -> Responsewhere T: Into<Body>,
The response with text/html; charset=utf-8
media type.
sourcefn json<T>(t: T) -> Result<Response, PayloadError>where
T: Serialize,
fn json<T>(t: T) -> Result<Response, PayloadError>where T: Serialize,
Available on crate feature
json
only.The response with application/javascript; charset=utf-8
media type.
Errors
Throws an error if serialization fails.