saluki_env/host/providers/
fixed.rs

1use async_trait::async_trait;
2use memory_accounting::{MemoryBounds, MemoryBoundsBuilder};
3use saluki_config::GenericConfiguration;
4use saluki_error::GenericError;
5
6use crate::HostProvider;
7
8/// Host provider based on a fixed hostname.
9#[derive(Clone)]
10pub struct FixedHostProvider {
11    hostname: String,
12}
13
14impl FixedHostProvider {
15    /// Creates a new `FixedHostProvider` from the given configuration.
16    ///
17    /// Depends on the hostname existing in the given configuration under the `hostname` key.
18    ///
19    /// # Errors
20    ///
21    /// If the hostname is not specified in the configuration, an error is returned.
22    pub fn from_configuration(config: &GenericConfiguration) -> Result<Self, GenericError> {
23        let hostname = config.get_typed::<String>("hostname")?;
24
25        Ok(Self { hostname })
26    }
27}
28
29#[async_trait]
30impl HostProvider for FixedHostProvider {
31    type Error = GenericError;
32
33    async fn get_hostname(&self) -> Result<String, Self::Error> {
34        Ok(self.hostname.clone())
35    }
36}
37
38impl MemoryBounds for FixedHostProvider {
39    fn specify_bounds(&self, builder: &mut MemoryBoundsBuilder) {
40        builder.minimum().with_single_value::<Self>("component struct");
41    }
42}