pub struct TokenManager { /* private fields */ }Expand description
Manages access_token lifecycle with automatic refresh. Uses single-flight pattern to merge concurrent refresh requests.
Implementations§
Source§impl TokenManager
impl TokenManager
pub fn new(client: WechatClient) -> Self
pub fn builder(client: WechatClient) -> TokenManagerBuilder
Sourcepub async fn get_token(&self) -> Result<String, WechatError>
pub async fn get_token(&self) -> Result<String, WechatError>
Get access token, using cache if available and not expired.
Automatically fetches a new token if:
- No cached token exists
- Cached token is expired or expiring soon (within refresh buffer)
Uses single-flight pattern to merge concurrent requests.
§Returns
The access token string.
§Errors
Returns WechatError::Api if WeChat returns an error code.
Returns WechatError::Http if network request fails.
Returns WechatError::Token if token parsing fails.
Sourcepub async fn invalidate(&self)
pub async fn invalidate(&self)
Invalidate cached token.
Call this when you know the current access token is no longer valid (e.g., after calling the WeChat auth ticket revoke API).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TokenManager
impl !RefUnwindSafe for TokenManager
impl Send for TokenManager
impl Sync for TokenManager
impl Unpin for TokenManager
impl UnsafeUnpin for TokenManager
impl !UnwindSafe for TokenManager
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