firebase_rs_sdk/platform/
token.rs1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug, Clone)]
6pub struct TokenError {
7 message: String,
8}
9
10impl TokenError {
11 pub fn new(message: impl Into<String>) -> Self {
12 Self {
13 message: message.into(),
14 }
15 }
16
17 pub fn from_error(err: impl Error) -> Self {
18 Self::new(err.to_string())
19 }
20}
21
22impl fmt::Display for TokenError {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 write!(f, "{}", self.message)
25 }
26}
27
28impl Error for TokenError {}
29
30#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
32#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
33pub trait AsyncTokenProvider: Send + Sync {
34 async fn get_token(&self, force_refresh: bool) -> Result<Option<String>, TokenError>;
35}