ProblemDetailsMapper

Struct ProblemDetailsMapper 

Source
pub struct ProblemDetailsMapper;

Implementations§

Source§

impl ProblemDetailsMapper

Source

pub fn map(error: Box<dyn Error>) -> Option<ProblemDetails>

Examples found in repository?
examples/custom_error_types.rs (line 43)
33fn main() {
34    // Setup the mapper settings
35    ProblemDetailsMapper::setup(|options| {
36        // will register the test error its own mapping
37        // provided by IntoProblemDetails.
38        options.map::<TestError>();
39    }).unwrap();
40
41    // Map an error to a Problem Details response
42    let error = TestError::new();
43    let problem_details = ProblemDetailsMapper::map(Box::new(error));
44
45    // Output the Problem Details response
46    println!("{:?}", problem_details);
47}
More examples
Hide additional examples
examples/basic_usage.rs (line 12)
3fn main() {
4    // Setup the mapper settings
5    ProblemDetailsMapper::setup(|options| {
6        // will map every error given to a http status code 500.
7        options.map_std_err();
8    }).unwrap();
9
10    // Map an error to a Problem Details response
11    let error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found");
12    let problem_details = ProblemDetailsMapper::map(Box::new(error));
13
14    // Output the Problem Details response
15    println!("{:?}", problem_details);
16}
Source

pub fn setup<F>(setup: F) -> Result<(), MapperError>
where F: Fn(&mut ProblemDetailsOptions),

Examples found in repository?
examples/custom_error_types.rs (lines 35-39)
33fn main() {
34    // Setup the mapper settings
35    ProblemDetailsMapper::setup(|options| {
36        // will register the test error its own mapping
37        // provided by IntoProblemDetails.
38        options.map::<TestError>();
39    }).unwrap();
40
41    // Map an error to a Problem Details response
42    let error = TestError::new();
43    let problem_details = ProblemDetailsMapper::map(Box::new(error));
44
45    // Output the Problem Details response
46    println!("{:?}", problem_details);
47}
More examples
Hide additional examples
examples/basic_usage.rs (lines 5-8)
3fn main() {
4    // Setup the mapper settings
5    ProblemDetailsMapper::setup(|options| {
6        // will map every error given to a http status code 500.
7        options.map_std_err();
8    }).unwrap();
9
10    // Map an error to a Problem Details response
11    let error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found");
12    let problem_details = ProblemDetailsMapper::map(Box::new(error));
13
14    // Output the Problem Details response
15    println!("{:?}", problem_details);
16}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.