pub struct TokenCache { /* private fields */ }Expand description
Manages reading and writing CachedToken values to a JSON file on disk.
On Unix systems, the token file is created with mode 0600 (owner read/write only).
Implementations§
Source§impl TokenCache
impl TokenCache
Sourcepub fn with_path(path: PathBuf) -> Self
pub fn with_path(path: PathBuf) -> Self
Creates a new TokenCache that reads from and writes to the given file path.
Sourcepub fn load(&self) -> Result<Option<CachedToken>>
pub fn load(&self) -> Result<Option<CachedToken>>
Loads a cached token from disk.
Returns None if the file does not exist, contains malformed or unrecognized
JSON, or holds an expired token. A corrupt cache is treated the same as an
absent one so the caller can prompt the user to log in again rather than
surfacing a raw deserialization error.
§Errors
Returns an error if the cache has insecure permissions or another filesystem I/O operation fails.
Sourcepub fn save(&self, token: &CachedToken) -> Result<()>
pub fn save(&self, token: &CachedToken) -> Result<()>
Serializes and writes the given token to disk with restricted file permissions.
Creates parent directories as needed so callers can pass a path whose
ancestors do not yet exist (e.g. ~/.rhood/.rhood-token on a fresh host).
Trait Implementations§
Source§impl Clone for TokenCache
impl Clone for TokenCache
Source§fn clone(&self) -> TokenCache
fn clone(&self) -> TokenCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more