ayun_environment/
instance.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::Environment;
use ayun_core::{
    errors::ContainerError,
    traits::{ErrorTrait, InstanceTrait},
    Container, Error, Result,
};

impl InstanceTrait for Environment {
    fn register(_: &Container) -> Result<Self, ContainerError> {
        let environment = match Self::try_from_args() {
            Ok(env) => env,
            Err(_) => Self::try_from_assertion().map_err(Error::wrap)?,
        };

        #[cfg(feature = "color-eyre")]
        if !environment.production() {
            color_eyre::install().expect("Failed to install color eyre");
        }

        Ok(environment)
    }
}