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: ETrait 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 T where
T: 'a,
impl<'a, T> AsTaggedExplicit<'a> for T where
T: 'a,
fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>
impl<'a, T> AsTaggedImplicit<'a> for T where
T: 'a,
impl<'a, T> AsTaggedImplicit<'a> for T where
T: 'a,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
sourcefn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more
