1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crateProblem;
/// Convert a value into an RFC 7807 [`Problem`].
///
/// Implement this trait on your application's error types to enable
/// automatic conversion into structured problem responses.
///
/// # Example
///
/// ```
/// use rust_rfc7807::{IntoProblem, Problem};
///
/// enum AppError {
/// UserNotFound(u64),
/// Unauthorized,
/// }
///
/// impl IntoProblem for AppError {
/// fn into_problem(self) -> Problem {
/// match self {
/// AppError::UserNotFound(id) => Problem::not_found()
/// .title("User not found")
/// .detail(format!("No user with ID {id}"))
/// .code("USER_NOT_FOUND"),
/// AppError::Unauthorized => Problem::unauthorized()
/// .title("Unauthorized")
/// .code("UNAUTHORIZED"),
/// }
/// }
/// }
/// ```