pub trait MagicCodeBackend: Send + Sync {
// Required methods
fn put(&self, email: &str, code: &MagicCode);
fn get(&self, email: &str) -> Option<MagicCode>;
fn remove(&self, email: &str);
fn bump_attempts(&self, email: &str);
fn load_all(&self) -> Vec<MagicCode>;
}Expand description
Pluggable storage for magic-code records. In-memory is the default
(fine for dev); persistent backends (SQLite, Postgres) live in
pylon-runtime so a server restart between “send code” and “verify
code” doesn’t invalidate the user’s pending login.
All methods are infallible from the caller’s perspective — durability is best-effort. A backend that fails to write should log; the in-memory cache remains authoritative for the current process.
Required Methods§
Sourcefn get(&self, email: &str) -> Option<MagicCode>
fn get(&self, email: &str) -> Option<MagicCode>
Look up the current code for email. Returns None if absent.
Sourcefn remove(&self, email: &str)
fn remove(&self, email: &str)
Remove the code for email (called on successful verify or
expiry). Idempotent — missing key is not an error.
Sourcefn bump_attempts(&self, email: &str)
fn bump_attempts(&self, email: &str)
Persist an attempts++ on the existing record without touching
other fields. Used by the verify-failed path to enforce
MAX_ATTEMPTS across restarts.