logo
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

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Returns Ok if a Response could be generated successfully. Otherwise, returns an Err with a failing Status. Read more

A sentinel that never aborts. The Responder impl for Debug will never be called, so it’s okay to not abort for failing T: Sentinel.

Returns true if launch should be aborted and false otherwise.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts self into a collection.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more