scuffle_bootstrap/
config.rs

1/// This trait is used to parse a configuration for the application.
2///
3/// The avoid having to manually implement this trait, the `bootstrap!` macro in
4/// the [`scuffle_settings`](../../scuffle_settings) crate can be used to
5/// generate an implementation.
6///
7/// # See Also
8///
9/// - [`Global`](crate::Global)
10/// - [`scuffle_settings`](../../scuffle_settings)
11pub trait ConfigParser: Sized {
12    fn parse() -> impl std::future::Future<Output = anyhow::Result<Self>>;
13}
14
15impl ConfigParser for () {
16    #[inline(always)]
17    fn parse() -> impl std::future::Future<Output = anyhow::Result<Self>> {
18        std::future::ready(Ok(()))
19    }
20}
21
22pub struct EmptyConfig;
23
24impl ConfigParser for EmptyConfig {
25    #[inline(always)]
26    fn parse() -> impl std::future::Future<Output = anyhow::Result<Self>> {
27        std::future::ready(Ok(EmptyConfig))
28    }
29}
30
31#[cfg(test)]
32#[cfg_attr(all(test, coverage_nightly), coverage(off))]
33mod tests {
34    use super::{ConfigParser, EmptyConfig};
35
36    #[tokio::test]
37    async fn unit_config() {
38        assert!(matches!(<()>::parse().await, Ok(())));
39    }
40
41    #[tokio::test]
42    async fn empty_config() {
43        assert!(matches!(EmptyConfig::parse().await, Ok(EmptyConfig)));
44    }
45}