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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Framework-neutral diagnostic identity, envelopes, and governance.
//!
//! Recourse applications declare stable diagnostic marker types, register them
//! explicitly, and construct protocol values through the resulting catalog.
//!
//! Public signatures name types from `http` 1, `schemars` 1, and `serde` 1;
//! [`dependencies`] re-exports each crate at that required major version.
//!
//! ```
//! use recourse::{
//! catalog::{Catalog, CatalogSpec, CodeNumber},
//! diagnostic::{DiagnosticType, NoEvidence},
//! http::{CorrelationId, Fixed, HttpProblemType, ProblemOccurrence},
//! };
//!
//! enum ServiceCatalog {}
//!
//! impl CatalogSpec for ServiceCatalog {
//! const NAME: &'static str = "example-service";
//! const PREFIX: &'static str = "EXM";
//! const TYPE_BASE: &'static str = "https://example.invalid/problems/";
//! }
//!
//! enum ResourceMissing {}
//!
//! impl DiagnosticType for ResourceMissing {
//! type Catalog = ServiceCatalog;
//! type Evidence = NoEvidence;
//!
//! const NUMBER: CodeNumber = CodeNumber::new(1001);
//! const TITLE: &'static str = "Resource missing";
//! const DETAIL: &'static str = "The requested resource does not exist.";
//! const SUGGESTIONS: &'static [&'static str] = &["Check the resource identifier."];
//! const DOCS: &'static str = "Verify the identifier before retrying.";
//! }
//!
//! impl HttpProblemType for ResourceMissing {
//! type Policy = Fixed<404>;
//! }
//!
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let catalog = Catalog::<ServiceCatalog>::builder()
//! .problem::<ResourceMissing>()
//! .build()?;
//! let occurrence = ProblemOccurrence::new(
//! CorrelationId::new("request-01")?,
//! "/problem-occurrences/request-01",
//! )?;
//! let encoded = catalog
//! .try_problem::<ResourceMissing>(occurrence, NoEvidence)?
//! .try_encode()?;
//!
//! assert_eq!(encoded.status().as_u16(), 404);
//! assert_eq!(encoded.headers()["content-type"], "application/problem+json");
//! # Ok(())
//! # }
//! # assert!(example().is_ok());
//! ```