#[non_exhaustive]pub struct DeclaredErrorCode {
pub code: &'static str,
pub retryable: bool,
}Expand description
An extended error code a Trust Task specification declares in its
errorCodes front matter (SPEC.md §7.3 item 9, §8.5).
trust-tasks-codegen emits one of these per declaration, as a constant in
the generated module’s error_codes submodule, and collects them into that
module’s ERROR_CODES slice. crate::schema_index::error_codes_for
serves the same slice by Type URI, for a consumer that dispatches on the URI
and has no module to name.
The point is that the code string is read from the specification, not
written at the call site. A hand-written literal can name a code the
specification never declared, and nothing notices: the consumer on the other
end degrades it to taskFailed (§8.5) and the distinction the specification
drew is lost without a trace.
use trust_tasks_rs::specs::acl::grant::v0_1 as grant;
// Emit it — `retryable` comes from the declaration, not a guess.
let payload: ErrorPayload = grant::error_codes::ROLE_NOT_RECOGNIZED.into();
// Or keep the wire string, in a `const` context.
const ROLE_NOT_RECOGNIZED: &str = grant::error_codes::ROLE_NOT_RECOGNIZED.code;#[non_exhaustive] so the declaration’s other members (meaning,
detailsSchema) can be carried later without a breaking change.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.code: &'static strThe fully qualified code as it appears on the wire, <namespace>:<local>
— e.g. "acl/grant:roleNotRecognized". The namespace is the declaring
specification’s slug or a family prefix of it (§8.5 rule 2).
retryable: boolThe retryable value the specification declares for this code — the
value an emitter SHOULD send (§8.4).
Implementations§
Source§impl DeclaredErrorCode
impl DeclaredErrorCode
Sourcepub fn namespace(&self) -> &'static str
pub fn namespace(&self) -> &'static str
The namespace before the colon: the declaring specification’s slug, or a family prefix of it.
Sourcepub fn matches(&self, code: &TrustTaskCode) -> bool
pub fn matches(&self, code: &TrustTaskCode) -> bool
Whether code is this declared code.
A method rather than PartialEq<DeclaredErrorCode> for TrustTaskCode:
a second PartialEq impl on TrustTaskCode makes every
assert_eq!(code, StandardCode::X.into()) ambiguous, which would break
consumers that compile today.
Compares namespace and local part, so a TrustTaskCode parsed off the
wire and one built with Payload::extended_code
both match.
Trait Implementations§
Source§impl Clone for DeclaredErrorCode
impl Clone for DeclaredErrorCode
Source§fn clone(&self) -> DeclaredErrorCode
fn clone(&self) -> DeclaredErrorCode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for DeclaredErrorCode
Source§impl Debug for DeclaredErrorCode
impl Debug for DeclaredErrorCode
Source§impl Display for DeclaredErrorCode
impl Display for DeclaredErrorCode
impl Eq for DeclaredErrorCode
Source§impl From<DeclaredErrorCode> for TrustTaskCode
impl From<DeclaredErrorCode> for TrustTaskCode
Source§fn from(declared: DeclaredErrorCode) -> TrustTaskCode
fn from(declared: DeclaredErrorCode) -> TrustTaskCode
Infallible: the generator refuses to emit a code that does not parse,
so a DeclaredErrorCode from crate::specs always converts.
Source§impl From<DeclaredErrorCode> for ErrorPayload
impl From<DeclaredErrorCode> for ErrorPayload
Source§fn from(declared: DeclaredErrorCode) -> ErrorPayload
fn from(declared: DeclaredErrorCode) -> ErrorPayload
An error payload carrying declared, with retryable set to the value
the specification declares rather than the §8.5 taskFailed default
ErrorPayload::new applies to an extended code it knows nothing about.
Source§impl Hash for DeclaredErrorCode
impl Hash for DeclaredErrorCode
Source§impl PartialEq for DeclaredErrorCode
impl PartialEq for DeclaredErrorCode
impl StructuralPartialEq for DeclaredErrorCode
Auto Trait Implementations§
impl Freeze for DeclaredErrorCode
impl RefUnwindSafe for DeclaredErrorCode
impl Send for DeclaredErrorCode
impl Sync for DeclaredErrorCode
impl Unpin for DeclaredErrorCode
impl UnsafeUnpin for DeclaredErrorCode
impl UnwindSafe for DeclaredErrorCode
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.