#[non_exhaustive]pub struct AppCode { /* private fields */ }Expand description
Stable machine-readable error code exposed to clients.
Values are serialized as SCREAMING_SNAKE_CASE strings (e.g.,
"NOT_FOUND"). This type is part of the public wire contract and supports
both built-in constants and caller-defined codes created via
AppCode::new or AppCode::try_new.
Design rules:
- Keep the set small and meaningful.
- Prefer adding new variants over overloading existing ones.
- Do not encode private/internal details in codes.
- Validate custom codes using
AppCode::try_newbefore exposing them publicly.
Implementations§
Source§impl AppCode
impl AppCode
Sourcepub const Validation: Self
pub const Validation: Self
Machine code emitted when validation fails.
Sourcepub const UserAlreadyExists: Self
pub const UserAlreadyExists: Self
Machine code emitted when attempting to create an existing user.
Machine code emitted when authentication fails or is required.
Sourcepub const NotImplemented: Self
pub const NotImplemented: Self
Machine code emitted when functionality is missing.
Sourcepub const BadRequest: Self
pub const BadRequest: Self
Machine code emitted when a request is malformed.
Sourcepub const RateLimited: Self
pub const RateLimited: Self
Machine code emitted when a caller is throttled.
Sourcepub const TelegramAuth: Self
pub const TelegramAuth: Self
Machine code emitted when Telegram authentication fails.
Sourcepub const InvalidJwt: Self
pub const InvalidJwt: Self
Machine code emitted when a JWT token is invalid.
Machine code emitted when dependencies are unavailable.
Sourcepub const Serialization: Self
pub const Serialization: Self
Machine code emitted for serialization failures.
Sourcepub const Deserialization: Self
pub const Deserialization: Self
Machine code emitted for deserialization failures.
Sourcepub const ExternalApi: Self
pub const ExternalApi: Self
Machine code emitted when an external API fails.
Sourcepub const fn new(code: &'static str) -> Self
pub const fn new(code: &'static str) -> Self
Construct an AppCode from a compile-time string literal.
§Examples
use masterror::AppCode;
let code = AppCode::new("INVALID_JSON");
assert_eq!(code.as_str(), "INVALID_JSON");§Panics
Panics when the literal is not SCREAMING_SNAKE_CASE. Use
AppCode::try_new to validate dynamic strings at runtime.
Sourcepub fn try_new(code: impl Into<String>) -> Result<Self, ParseAppCodeError>
pub fn try_new(code: impl Into<String>) -> Result<Self, ParseAppCodeError>
Construct an AppCode from a dynamically provided string.
The input must be SCREAMING_SNAKE_CASE. This constructor allocates to own the string, making it suitable for runtime-defined codes.
§Errors
Returns ParseAppCodeError when the string is empty or contains
characters outside of A-Z, 0-9, and _.
§Examples
use masterror::AppCode;
let code = AppCode::try_new(String::from("THIRD_PARTY_FAILURE"))?;
assert_eq!(code.as_str(), "THIRD_PARTY_FAILURE");Trait Implementations§
Source§impl<'de> Deserialize<'de> for AppCode
impl<'de> Deserialize<'de> for AppCode
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<AppErrorKind> for AppCode
impl From<AppErrorKind> for AppCode
Source§fn from(kind: AppErrorKind) -> Self
fn from(kind: AppErrorKind) -> Self
Map internal taxonomy (AppErrorKind) to public machine code
(AppCode).
The mapping is 1:1 today and intentionally conservative.
Source§impl FromStr for AppCode
Parse an AppCode from its canonical string representation.
impl FromStr for AppCode
Parse an AppCode from its canonical string representation.
§Errors
Returns ParseAppCodeError when the input is not SCREAMING_SNAKE_CASE.
§Examples
use std::str::FromStr;
use masterror::{AppCode, ParseAppCodeError};
let code = AppCode::from_str("NOT_FOUND")?;
assert_eq!(code, AppCode::NotFound);