Skip to main content

microvms_edges/
env.rs

1// SPDX-License-Identifier: Apache-2.0
2//! The process environment, as the lookup this crate's resolvers take.
3//!
4//! [`Region::from_env`](crate::Region::from_env),
5//! [`FileNameStore::default_location`](crate::names::FileNameStore::default_location) and the
6//! other resolvers take a `&dyn Fn(&str) -> Option<String>` rather than reading `std::env`
7//! themselves, so a caller (and a test) decides where the variables come from. [`process`] is
8//! that lookup in production. It lives here once so the CLI and both bindings pass the same
9//! function: a driving adapter never reads the environment itself, and its `clippy.toml` bans
10//! `std::env::var` to keep it that way. The adapters' `clippy.toml` bans calling [`process`]
11//! by name too, since that's the same read with a different path. Each adapter hands it to a
12//! resolver at the one place it composes them, under a listed `#[expect]`.
13
14/// `name`'s value in the process environment, or `None` when it's unset or isn't valid Unicode.
15pub fn process(name: &str) -> Option<String> {
16    std::env::var(name).ok()
17}