use std::fmt::{Debug, Formatter};
use std::sync::Arc;
use async_trait::async_trait;
use config::{AsyncSource, ConfigError, Map, Value};
use crate::client::Inner;
#[derive(Clone)]
pub struct Source {
inner: Arc<Inner>,
}
impl Source {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
}
impl Debug for Source {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("Source")
.field("app_id", &self.inner.options.app_id)
.finish()
}
}
#[async_trait]
impl AsyncSource for Source {
async fn collect(&self) -> Result<Map<String, Value>, ConfigError> {
self.inner
.ensure_loaded()
.await
.map_err(|error| ConfigError::Foreign(Box::new(error)))?;
Ok(self.inner.snapshot().to_config_map())
}
}