Skip to main content

r402_protocol/error/
problem.rs

1//! Internal bridge from Rust errors to wire reason codes.
2
3use super::ErrorReason;
4
5/// Structured payment-problem record used at verify/settle boundaries.
6///
7/// Not itself serializable.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct PaymentProblem {
10    reason: ErrorReason,
11    details: String,
12}
13
14impl PaymentProblem {
15    /// Creates a new problem record.
16    #[must_use]
17    pub const fn new(reason: ErrorReason, details: String) -> Self {
18        Self { reason, details }
19    }
20
21    /// Wire-level reason code.
22    #[must_use]
23    pub fn reason(&self) -> ErrorReason {
24        self.reason.clone()
25    }
26
27    /// Borrowed wire-level reason code.
28    #[must_use]
29    pub const fn reason_ref(&self) -> &ErrorReason {
30        &self.reason
31    }
32
33    /// Human-readable details.
34    #[must_use]
35    pub fn details(&self) -> &str {
36        &self.details
37    }
38}
39
40/// Converts an error into a [`PaymentProblem`].
41pub trait AsPaymentProblem {
42    /// Canonical wire-level payment problem.
43    fn as_payment_problem(&self) -> PaymentProblem;
44}