saluki_env/
lib.rs

1//! Helpers for querying environment-specific data.
2//!
3//! In many cases, a Saluki service will need to interact with the environment in which it is running. This may include
4//! interacting with the operating system, introspecting workloads running on the host, and so on.
5//!
6//! This crate provides implementations of various "providers" -- specific facets of the environment that can be queried
7//! -- for a number of different environments, such as bare metal hosts, Kubernetes clusters, and so on.
8#![deny(warnings)]
9#![deny(missing_docs)]
10
11pub mod autodiscovery;
12pub mod configstream;
13pub mod features;
14pub mod helpers;
15pub mod host;
16pub mod workload;
17
18use std::sync::Arc;
19
20pub use self::autodiscovery::AutodiscoveryProvider;
21pub use self::host::HostProvider;
22pub use self::workload::WorkloadProvider;
23
24/// Provides information about the environment in which the process is running.
25pub trait EnvironmentProvider {
26    /// Type of the host provider.
27    type Host: self::host::HostProvider;
28
29    /// Type of the workload provider.
30    type Workload: self::workload::WorkloadProvider;
31
32    /// Type of the autodiscovery provider.
33    type AutodiscoveryProvider: self::autodiscovery::AutodiscoveryProvider;
34
35    /// Gets a reference to the host provider for this environment.
36    fn host(&self) -> &Self::Host;
37
38    /// Gets a reference to workload provider for this environment.
39    fn workload(&self) -> &Self::Workload;
40
41    /// Gets a reference to autodiscovery provider for this environment.
42    fn autodiscovery(&self) -> &Self::AutodiscoveryProvider;
43}
44
45impl<E> EnvironmentProvider for Arc<E>
46where
47    E: EnvironmentProvider,
48{
49    type Host = E::Host;
50    type Workload = E::Workload;
51    type AutodiscoveryProvider = E::AutodiscoveryProvider;
52
53    fn host(&self) -> &Self::Host {
54        (**self).host()
55    }
56
57    fn workload(&self) -> &Self::Workload {
58        (**self).workload()
59    }
60
61    fn autodiscovery(&self) -> &Self::AutodiscoveryProvider {
62        (**self).autodiscovery()
63    }
64}