statsig_rust/id_lists_adapter/
id_lists_adapter_trait.rs1use crate::{StatsigErr, StatsigRuntime};
2use async_trait::async_trait;
3use std::sync::Arc;
4use std::time::Duration;
5use std::{collections::HashMap, fmt};
6
7use serde::{Deserialize, Serialize};
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
10#[serde(rename_all = "camelCase")]
11pub struct IdListMetadata {
12 pub name: String,
13 pub url: String,
14
15 #[serde(rename = "fileID")]
16 pub file_id: Option<String>,
17
18 pub size: u64,
19 pub creation_time: i64,
20}
21
22pub struct IdListUpdate {
23 pub raw_changeset: Option<String>,
24 pub new_metadata: IdListMetadata,
25}
26
27#[async_trait]
28pub trait IdListsAdapter: Send + Sync {
29 async fn start(
37 self: Arc<Self>,
38 statsig_runtime: &Arc<StatsigRuntime>,
39 listener: Arc<dyn IdListsUpdateListener + Send + Sync>,
40 ) -> Result<(), StatsigErr>;
41
42 async fn shutdown(&self, timeout: Duration) -> Result<(), StatsigErr>;
49
50 async fn schedule_background_sync(
57 self: Arc<Self>,
58 statsig_runtime: &Arc<StatsigRuntime>,
59 ) -> Result<(), StatsigErr>;
60
61 fn get_type_name(&self) -> String;
63}
64
65pub trait IdListsUpdateListener: Send + Sync {
66 fn get_current_id_list_metadata(&self) -> HashMap<String, IdListMetadata>;
67
68 fn did_receive_id_list_updates(&self, updates: HashMap<String, IdListUpdate>);
69}
70
71impl fmt::Debug for dyn IdListsAdapter {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 write!(f, "{}", self.get_type_name())
74 }
75}