[−][src]Struct hreq::server::Reply
Concrete return type from endpoints and middleware.
This type will rarely be used directly. The return signature of endpoints and
middleware is impl Into<Reply>
. As a user of this crate you would prefer
using one of the return types possible via the Into
trait.
Return type | Response | Notes |
---|---|---|
() | text/plain | "" |
&str | text/plain | "Hello" |
String | text/plain | "Hello".to_string() |
&String | text/plain | &"Hello".to_string() |
&[u8] | application/octet-stream | b"abcdef" |
Vec<u8> | application/octet-stream | vec![65,66,67] |
&Vec<u8> | application/octet-stream | &vec![65,66,67] |
std::fs::File | application/octet-stream | NB. Only with tokio |
Body | Body determined | |
Result<Into<Body>, Into<Error>> | See Body | |
Response<Into<Body>> | Response and fallback to Body | |
Result<Response<Into<Body>>, Into<Error>> | Response and falllback to Body | |
Option<Into<Reply>> | 404 on None |
Examples
async fn handle(req: http::Request<hreq::Body>) { // 200 with empty reply }
async fn handle(req: http::Request<hreq::Body>) -> &'static str { "Hello World!" // 200 with text/plain body }
async fn handle(req: http::Request<hreq::Body>) -> &'static str { "Hello World!" // 200 with text/plain body }
async fn handle(req: http::Request<hreq::Body>) -> String { format!("Hello there {}", req.uri().path()) // 200 with text/plain body }
async fn handle(req: http::Request<hreq::Body>) -> &'static [u8] { &[79, 75, 10] // 200 with application/octet-stream }
async fn handle(req: http::Request<hreq::Body>) -> Vec<u8> { vec![79, 75, 10] // 200 with application/octet-stream }
use hreq::Body; async fn handle(req: http::Request<Body>) -> Body { let data = vec![79, 75, 10]; let len = data.len() as u64; let cursor = std::io::Cursor::new(data); Body::from_sync_read(cursor, Some(len)) // check Body doc for more }
use hreq::Body; async fn handle( req: http::Request<Body> ) -> Result<&'static str, hreq::Error> { let file = std::fs::File::open("/etc/bashrc")?; Ok("File opened OK") }
use hreq::prelude::*; async fn handle(req: http::Request<hreq::Body>) -> http::Response<()> { http::Response::builder() .status(302) .header("location", "/see-my-other-page") .body(()) .unwrap() }
use hreq::prelude::*; async fn handle( req: http::Request<hreq::Body> ) -> http::Response<&'static str> { http::Response::builder() .header("X-My-Exotic-Header", "Cool") .body("Hello World!") .unwrap() }
use hreq::prelude::*; async fn handle( req: http::Request<hreq::Body> ) -> Result<http::Response<String>, hreq::Error> { let no = 42; Ok(http::Response::builder() .header("X-My-Exotic-Header", "Cool") .body(format!("Hello World!, {}", no))?) }
use hreq::prelude::*; async fn handle( req: http::Request<hreq::Body> ) -> Option<String> { let no = 42; Some(format!("Hello World!, {}", no)) }
Implementations
impl Reply
[src]
Trait Implementations
impl Debug for Reply
[src]
impl<'a> From<&'a [u8]> for Reply
[src]
impl<'a> From<&'a String> for Reply
[src]
impl<'a> From<&'a Vec<u8>> for Reply
[src]
impl<'a> From<&'a str> for Reply
[src]
impl<'a> From<()> for Reply
[src]
impl From<Body> for Reply
[src]
impl<R> From<Option<R>> for Reply where
R: Into<Reply>,
[src]
R: Into<Reply>,
impl<B> From<Response<B>> for Reply where
B: Into<Body>,
[src]
B: Into<Body>,
impl<B, E> From<Result<B, E>> for Reply where
B: Into<Body>,
E: Into<Error>,
[src]
B: Into<Body>,
E: Into<Error>,
impl<B, E> From<Result<Response<B>, E>> for Reply where
B: Into<Body>,
E: Into<Error>,
[src]
B: Into<Body>,
E: Into<Error>,
impl From<String> for Reply
[src]
impl From<Vec<u8>> for Reply
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Reply
impl Send for Reply
impl Sync for Reply
impl Unpin for Reply
impl !UnwindSafe for Reply
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,