soph_redis/support/
instance.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
use crate::{async_trait, config, error::Error, Redis};
use soph_config::support::config;
use soph_core::{
    error::ContainerError,
    support::{app, Container},
    traits::{ErrorTrait, InstanceTrait},
    Result,
};

#[async_trait]
impl InstanceTrait for Redis {
    type Config = config::Redis;

    async fn register(_: &Container) -> Result<Self, ContainerError>
    where
        Self: Sized,
    {
        let config = config().parse::<Self::Config>()?;

        Ok(Self::try_from_config(config).await.map_err(Error::wrap)?)
    }

    async fn boot() -> Result<(), ContainerError>
    where
        Self: Sized,
    {
        let redis = app().resolve::<Self>()?;

        redis.ping().await.map_err(Error::wrap)?;

        Ok(())
    }
}