Struct rocket::response::Debug [−][src]
pub struct Debug<E>(pub E);
Expand description
Debug prints the internal value before responding with a 500 error.
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
.
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::io::{self, Read}; use rocket::Data; use rocket::response::Debug; #[post("/", format = "plain", data = "<data>")] fn post(data: Data) -> Result<String, Debug<io::Error>> { let mut name = String::with_capacity(32); data.open().take(32).read_to_string(&mut name)?; Ok(name) }
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) }
Trait Implementations
Auto Trait Implementations
impl<E> RefUnwindSafe for Debug<E> where
E: RefUnwindSafe,
E: RefUnwindSafe,
impl<E> Send for Debug<E> where
E: Send,
E: Send,
impl<E> Sync for Debug<E> where
E: Sync,
E: Sync,
impl<E> Unpin for Debug<E> where
E: Unpin,
E: Unpin,
impl<E> UnwindSafe for Debug<E> where
E: UnwindSafe,
E: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> IntoCollection<T> for T
[src]
impl<T> IntoCollection<T> for T
[src]pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
[src]
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
[src]Converts self
into a collection.
pub fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
[src]
F: FnMut(T) -> U,
A: Array<Item = U>,
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,