Skip to main content

trojan_auth/store/
record.rs

1//! Universal user record from any store.
2
3use super::cache::CachedUser;
4
5/// User data returned by a [`UserStore`](super::UserStore) implementation.
6///
7/// This is the common representation of a user across all backends.
8/// Validation logic lives in [`StoreAuth`](super::StoreAuth), not in the store itself.
9#[derive(Debug, Clone)]
10pub struct UserRecord {
11    /// Optional user identifier (for traffic recording and logging).
12    pub user_id: Option<String>,
13    /// Traffic limit in bytes (0 = unlimited). Uses `i64` to match DB column types.
14    pub traffic_limit: i64,
15    /// Traffic already used in bytes.
16    pub traffic_used: i64,
17    /// Expiration as Unix timestamp (0 = never expires).
18    pub expires_at: i64,
19    /// Whether the account is enabled.
20    pub enabled: bool,
21}
22
23impl From<CachedUser> for UserRecord {
24    fn from(cached: CachedUser) -> Self {
25        Self {
26            user_id: cached.user_id,
27            traffic_limit: cached.traffic_limit,
28            traffic_used: cached.traffic_used,
29            expires_at: cached.expires_at,
30            enabled: cached.enabled,
31        }
32    }
33}