pub struct CachedToken {
pub token: String,
pub expires_at: Instant,
pub token_type: String,
}Expand description
A cached authentication token with expiration tracking.
This struct holds an authentication token along with its expiration time to enable efficient token caching and refresh logic.
Fields§
§token: StringThe authentication token string
expires_at: InstantWhen the token expires
token_type: StringThe type of token (e.g., “Bearer”)
Implementations§
Source§impl CachedToken
impl CachedToken
Sourcepub fn new(token: String, expires_in: Duration, token_type: String) -> Self
pub fn new(token: String, expires_in: Duration, token_type: String) -> Self
Creates a new cached token with the given parameters.
§Arguments
token- The authentication token stringexpires_in- Duration until the token expirestoken_type- The type of token (e.g., “Bearer”)
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Checks if the token has expired.
§Returns
true if the token has passed its expiration time, false otherwise.
Sourcepub fn needs_refresh(&self) -> bool
pub fn needs_refresh(&self) -> bool
Checks if the token needs to be refreshed soon.
Uses a 5-minute buffer before expiration to ensure tokens are refreshed before they actually expire.
§Returns
true if the token should be refreshed, false otherwise.
Trait Implementations§
Source§impl Clone for CachedToken
impl Clone for CachedToken
Source§fn clone(&self) -> CachedToken
fn clone(&self) -> CachedToken
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CachedToken
impl RefUnwindSafe for CachedToken
impl Send for CachedToken
impl Sync for CachedToken
impl Unpin for CachedToken
impl UnwindSafe for CachedToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more