pub struct Debug<E>(pub E);
Expand description
Debug prints the internal value before forwarding to the 500 error catcher.
This value exists primarily to allow handler return types that would not
otherwise implement Responder
. It is typically used in conjunction with
Result<T, E>
where E
implements Debug
but not Responder
.
Note that because of it’s common use as an error value, std::io::Error
does implement Responder
. As a result, a std::io::Result<T>
can be
returned directly without the need for Debug
:
use std::io;
use rocket::fs::NamedFile;
#[get("/")]
async fn index() -> io::Result<NamedFile> {
NamedFile::open("index.html").await
}
Example
Because of the generic From<E>
implementation for Debug<E>
, conversions
from Result<T, E>
to Result<T, Debug<E>>
through ?
occur
automatically:
use std::string::FromUtf8Error;
use rocket::response::Debug;
#[get("/")]
fn rand_str() -> Result<String, Debug<FromUtf8Error>> {
let bytes: Vec<u8> = random_bytes();
Ok(String::from_utf8(bytes)?)
}
It is also possible to map the error directly to Debug
via
Result::map_err()
:
use std::string::FromUtf8Error;
use rocket::response::Debug;
#[get("/")]
fn rand_str() -> Result<String, Debug<FromUtf8Error>> {
let bytes: Vec<u8> = random_bytes();
String::from_utf8(bytes).map_err(Debug)
}
Tuple Fields§
§0: E
Trait Implementations§
Auto Trait Implementations§
impl<E> RefUnwindSafe for Debug<E>where E: RefUnwindSafe,
impl<E> Send for Debug<E>where E: Send,
impl<E> Sync for Debug<E>where E: Sync,
impl<E> Unpin for Debug<E>where E: Unpin,
impl<E> UnwindSafe for Debug<E>where E: UnwindSafe,
Blanket Implementations§
§impl<'a, T> AsTaggedExplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,
§impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,
§impl<T> FromFd for Twhere
T: From<OwnedFd>,
impl<T> FromFd for Twhere T: From<OwnedFd>,
§impl<T> FromFilelike for Twhere
T: From<OwnedFd>,
impl<T> FromFilelike for Twhere T: From<OwnedFd>,
§fn from_filelike(owned: OwnedFd) -> T
fn from_filelike(owned: OwnedFd) -> T
Constructs a new instance of
Self
from the given filelike object. Read more§fn from_into_filelike<Owned>(owned: Owned) -> Twhere
Owned: IntoFilelike,
fn from_into_filelike<Owned>(owned: Owned) -> Twhere Owned: IntoFilelike,
Constructs a new instance of
Self
from the given filelike object
converted from into_owned
. Read more§impl<T> FromSocketlike for Twhere
T: From<OwnedFd>,
impl<T> FromSocketlike for Twhere T: From<OwnedFd>,
§fn from_socketlike(owned: OwnedFd) -> T
fn from_socketlike(owned: OwnedFd) -> T
Constructs a new instance of
Self
from the given socketlike object.§fn from_into_socketlike<Owned>(owned: Owned) -> Twhere
Owned: IntoSocketlike,
fn from_into_socketlike<Owned>(owned: Owned) -> Twhere Owned: IntoSocketlike,
Constructs a new instance of
Self
from the given socketlike object
converted from into_owned
.