scuffle_bootstrap/
config.rs

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

impl ConfigParser for () {
    #[inline(always)]
    fn parse() -> impl std::future::Future<Output = anyhow::Result<Self>> {
        std::future::ready(Ok(()))
    }
}

pub struct EmptyConfig;

impl ConfigParser for EmptyConfig {
    #[inline(always)]
    fn parse() -> impl std::future::Future<Output = anyhow::Result<Self>> {
        std::future::ready(Ok(EmptyConfig))
    }
}

#[cfg(test)]
#[cfg_attr(all(test, coverage_nightly), coverage(off))]
mod tests {
    use super::{ConfigParser, EmptyConfig};

    #[tokio::test]
    async fn unit_config() {
        assert!(matches!(<()>::parse().await, Ok(())));
    }

    #[tokio::test]
    async fn empty_config() {
        assert!(matches!(EmptyConfig::parse().await, Ok(EmptyConfig)));
    }
}