Skip to main content

CredentialStore

Trait CredentialStore 

Source
pub trait CredentialStore: Send + Sync {
    // Required methods
    fn load(&self) -> Result<Option<Credentials>, AuthError>;
    fn save(&self, credentials: &Credentials) -> Result<(), AuthError>;
    fn clear(&self) -> Result<(), AuthError>;
}
Expand description

凭据存储抽象。

实现方按自身介质决定持久化方式(加密文件 / 内存 / KMS / Redis 等); save 必须整体覆盖写入(bot 与 token 原子更新)。

Required Methods§

Source

fn load(&self) -> Result<Option<Credentials>, AuthError>

读取凭据;无凭据时返回 None

§Errors

存储介质故障(IO / 远端不可达)时返回 AuthError::Storage; 凭据缺失或解密失败不算错误(返回 None,与「未授权」表现一致)。

Source

fn save(&self, credentials: &Credentials) -> Result<(), AuthError>

整体覆盖写入凭据。

§Errors

写入失败时返回 AuthError::Storage

Source

fn clear(&self) -> Result<(), AuthError>

清除凭据(无凭据时应为 no-op)。

§Errors

删除失败时返回 AuthError::Storage

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§