Skip to main content

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 features;
13pub mod helpers;
14pub mod host;
15pub mod workload;
16
17use std::sync::Arc;
18
19pub use self::autodiscovery::AutodiscoveryProvider;
20pub use self::host::HostProvider;
21pub use self::workload::WorkloadProvider;
22
23/// Provides information about the environment in which the process is running.
24pub trait EnvironmentProvider {
25    /// Type of the host provider.
26    type Host: self::host::HostProvider;
27
28    /// Type of the workload provider.
29    type Workload: self::workload::WorkloadProvider;
30
31    /// Type of the autodiscovery provider.
32    type AutodiscoveryProvider: self::autodiscovery::AutodiscoveryProvider;
33
34    /// Gets a reference to the host provider for this environment.
35    fn host(&self) -> &Self::Host;
36
37    /// Gets a reference to workload provider for this environment.
38    fn workload(&self) -> &Self::Workload;
39
40    /// Gets a reference to autodiscovery provider for this environment.
41    fn autodiscovery(&self) -> &Self::AutodiscoveryProvider;
42}
43
44impl<E> EnvironmentProvider for Arc<E>
45where
46    E: EnvironmentProvider,
47{
48    type Host = E::Host;
49    type Workload = E::Workload;
50    type AutodiscoveryProvider = E::AutodiscoveryProvider;
51
52    fn host(&self) -> &Self::Host {
53        (**self).host()
54    }
55
56    fn workload(&self) -> &Self::Workload {
57        (**self).workload()
58    }
59
60    fn autodiscovery(&self) -> &Self::AutodiscoveryProvider {
61        (**self).autodiscovery()
62    }
63}