Skip to main content

ServerEnv

Struct ServerEnv 

Source
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, case-insensitively as Windows compares names): 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. Neither lets the table outgrow what the host can pass to a process: HostOs::max_env_entry_bytes for one entry and MAX_ENV_TOTAL_BYTES for all.

The host is not serialized: a deserialized table is always for HostOs::CURRENT, and converting into a map drops it. Other hosts exist so tests can model them (Windows name folding on any build).

§Examples

use mcpls_core::config::{EnvKey, EnvValue, HostOs, ServerEnv};

let mut env = ServerEnv::new(HostOs::Windows);
env.insert(EnvKey::new("Path").unwrap(), EnvValue::new("/a").unwrap())?;
assert_eq!(env.get("PATH"), Some("/a"));

env.insert(EnvKey::new("PATH").unwrap(), EnvValue::new("/b").unwrap())?;
assert_eq!(env.len(), 1);

let mut other = ServerEnv::new(HostOs::Other);
other.insert(EnvKey::new("Path").unwrap(), EnvValue::new("/a").unwrap())?;
assert_eq!(other.get("PATH"), None);

Implementations§

Source§

impl ServerEnv

Source

pub const fn new(host: HostOs) -> Self

An empty table whose names compare as host compares them.

Source

pub fn from_entries( entries: impl IntoIterator<Item = (EnvKey, EnvValue)>, host: HostOs, ) -> Result<Self, InvalidServerEnv>

Builds the table from entries, as host compares names.

§Errors

InvalidServerEnv::Duplicate when two keys name one variable on host, InvalidServerEnv::TooLarge when an entry or the table is too large to pass to a process there.

Source

pub const fn host(&self) -> HostOs

The host whose name comparison this table follows.

Source

pub fn get(&self, key: &str) -> Option<&str>

The value of key, looked up as the table’s host compares names.

Source

pub fn contains_key(&self, key: &str) -> bool

Whether key is set, as the table’s host compares names.

Source

pub fn insert( &mut self, key: EnvKey, value: EnvValue, ) -> Result<(), EnvTooLarge>

Sets key, replacing the spelling of it that the table’s host treats as the same variable.

§Errors

EnvTooLarge when the entry is over HostOs::max_env_entry_bytes or the table would be over MAX_ENV_TOTAL_BYTES, the sizes past which a spawn fails with E2BIG; the table is left as it was.

Source

pub fn iter(&self) -> impl Iterator<Item = (&EnvKey, &EnvValue)>

The entries, ordered by the host’s comparison of the name.

Source

pub fn len(&self) -> usize

The number of variables set.

Source

pub fn is_empty(&self) -> bool

Whether no variable is set.

Trait Implementations§

Source§

impl Clone for ServerEnv

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServerEnv

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServerEnv

An empty table for HostOs::CURRENT.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for ServerEnv

Source§

impl From<ServerEnv> for BTreeMap<EnvKey, String>

The entries without the table’s host, which is not serialized.

Source§

fn from(env: ServerEnv) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ServerEnv

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ServerEnv

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more