pub struct ServerEnv { /* private fields */ }Expand description
Environment variable overrides for a server process.
Holds at most one key per variable as the host compares names (exactly on
Unix, ASCII-case-insensitively on Windows): the table is indexed by the
host’s comparison of the name, so a lookup or a write cannot meet two
spellings of one variable and mcpls resolves the same value the child
process sees. The host is fixed at construction, so a table built for one
host cannot be read or extended as another. Keys come in through
Self::from_entries, which rejects collisions, or Self::insert,
which replaces them.
§Examples
use mcpls_core::config::{EnvKey, ServerEnv};
use mcpls_core::lsp::HostOs;
let mut env = ServerEnv::new(HostOs::Windows);
env.insert(EnvKey::new("Path").unwrap(), "/a".to_owned());
assert_eq!(env.get("PATH"), Some("/a"));
env.insert(EnvKey::new("PATH").unwrap(), "/b".to_owned());
assert_eq!(env.len(), 1);
let mut other = ServerEnv::new(HostOs::Other);
other.insert(EnvKey::new("Path").unwrap(), "/a".to_owned());
assert_eq!(other.get("PATH"), None);Implementations§
Source§impl ServerEnv
impl ServerEnv
Sourcepub const fn new(host: HostOs) -> Self
pub const fn new(host: HostOs) -> Self
An empty table whose names compare as host compares them.
Sourcepub fn from_entries(
entries: impl IntoIterator<Item = (EnvKey, String)>,
host: HostOs,
) -> Result<Self, DuplicateEnvKey>
pub fn from_entries( entries: impl IntoIterator<Item = (EnvKey, String)>, host: HostOs, ) -> Result<Self, DuplicateEnvKey>
Builds the table from entries, as host compares names.
§Errors
DuplicateEnvKey when two keys name one variable on host.
Sourcepub fn get(&self, key: &str) -> Option<&str>
pub fn get(&self, key: &str) -> Option<&str>
The value of key, looked up as the table’s host compares names.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Whether key is set, as the table’s host compares names.
Sourcepub fn insert(&mut self, key: EnvKey, value: String)
pub fn insert(&mut self, key: EnvKey, value: String)
Sets key, replacing the spelling of it that the table’s host treats
as the same variable.
Trait Implementations§
impl Eq for ServerEnv
impl StructuralPartialEq for ServerEnv
Auto Trait Implementations§
impl Freeze for ServerEnv
impl RefUnwindSafe for ServerEnv
impl Send for ServerEnv
impl Sync for ServerEnv
impl Unpin for ServerEnv
impl UnsafeUnpin for ServerEnv
impl UnwindSafe for ServerEnv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.