agile_config_client/
source.rs1use std::fmt::{Debug, Formatter};
4use std::sync::Arc;
5
6use async_trait::async_trait;
7use config::{AsyncSource, ConfigError, Map, Value};
8
9use crate::client::Inner;
10
11#[derive(Clone)]
17pub struct Source {
18 inner: Arc<Inner>,
19}
20
21impl Source {
22 pub(crate) fn new(inner: Arc<Inner>) -> Self {
23 Self { inner }
24 }
25}
26
27impl Debug for Source {
28 fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
29 formatter
30 .debug_struct("Source")
31 .field("app_id", &self.inner.options.app_id)
32 .finish()
33 }
34}
35
36#[async_trait]
37impl AsyncSource for Source {
38 async fn collect(&self) -> Result<Map<String, Value>, ConfigError> {
39 self.inner
40 .ensure_loaded()
41 .await
42 .map_err(|error| ConfigError::Foreign(Box::new(error)))?;
43 Ok(self.inner.snapshot().to_config_map())
44 }
45}