Skip to main content

alice_auth/
errors.rs

1//! errors.
2
3use core::fmt;
4
5// ============================================================================
6// Error (zero .rodata, no match)
7// ============================================================================
8
9/// Authentication error codes (E1–E5). Zero `.rodata` in release builds.
10#[derive(Clone, Copy, PartialEq, Eq)]
11#[repr(u8)]
12pub enum AuthError {
13    E1 = 1,
14    E2 = 2,
15    E3 = 3,
16    E4 = 4,
17    E5 = 5,
18}
19
20impl fmt::Display for AuthError {
21    #[inline(always)]
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        // 0.5.1: release でも同じ出力 (以前は release で空文字列 = silent no-op)
24        let c = [b'E', b'0' + (*self as u8)];
25        f.write_str(unsafe { core::str::from_utf8_unchecked(&c) })
26    }
27}
28
29impl fmt::Debug for AuthError {
30    #[inline(always)]
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        fmt::Display::fmt(self, f)
33    }
34}
35
36pub type Result<T> = core::result::Result<T, AuthError>;