Trait highnoon::responder::Responder [−][src]
This trait is implemented for all the common types you can return from an endpoint
It's also implemented for Response
and hyper::Response
for compatibility.
There is an implementation for Result<R> where R: Responder
which allows fallible
functions to be used as endpoints
use highnoon::{Request, Responder, Json, StatusCode}; fn example_1(_: Request<()>) -> impl Responder { // return status code StatusCode::NOT_FOUND } fn example_2(_: Request<()>) -> impl Responder { // return strings (&str or String) "Hello World" } fn example_3(_: Request<()>) -> impl Responder { // return status code with data (StatusCode::NOT_FOUND, "Not found!") } fn example_4(_: Request<()>) -> impl Responder { // return JSON data - for any type implementing `serde::Serialize` Json(vec![1, 2, 3]) } fn example_5(_: Request<()>) -> highnoon::Result<impl Responder> { // fallible functions too // (also works the return type as `impl Responder` as long as Rust can infer // the function returns `highnoon::Result`) Ok((StatusCode::CONFLICT, "Already Exists")) }
Required methods
fn into_response(self) -> Result<Response>
[src]
Implementations on Foreign Types
impl Responder for String
[src]
fn into_response(self) -> Result<Response>
[src]
impl Responder for &str
[src]
fn into_response(self) -> Result<Response>
[src]
impl Responder for &[u8]
[src]
fn into_response(self) -> Result<Response>
[src]
impl Responder for Vec<u8>
[src]
fn into_response(self) -> Result<Response>
[src]
impl<R: Responder> Responder for (StatusCode, R)
[src]
fn into_response(self) -> Result<Response>
[src]
impl<R: Responder> Responder for Option<R>
[src]
Returns StatusCode::NotFound
for None
, and the inner value for Some
fn into_response(self) -> Result<Response>
[src]
impl Responder for Response<Body>
[src]
Compatibility with the inner hyper::Response
fn into_response(self) -> Result<Response>
[src]
Implementors
impl Responder for Error
[src]
fn into_response(self) -> Result<Response>
[src]
impl Responder for highnoon::response::Response
[src]
Identity implementation