pub struct ProblemDetailsMapper;Implementations§
Source§impl ProblemDetailsMapper
impl ProblemDetailsMapper
Sourcepub fn map(error: Box<dyn Error>) -> Option<ProblemDetails>
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
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}Sourcepub fn setup<F>(setup: F) -> Result<(), MapperError>where
F: Fn(&mut ProblemDetailsOptions),
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
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§
impl Freeze for ProblemDetailsMapper
impl RefUnwindSafe for ProblemDetailsMapper
impl Send for ProblemDetailsMapper
impl Sync for ProblemDetailsMapper
impl Unpin for ProblemDetailsMapper
impl UnwindSafe for ProblemDetailsMapper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more