Skip to main content

EnvList

Struct EnvList 

Source
pub struct EnvList(/* private fields */);
Expand description

A PAM environment list

The PAM environment represents the contents of the regular environment variables of the authenticated user when service is granted and can be used to prepare the environment of child processes run as the authenticated user.

See Context::envlist().

§Examples

// Print the PAM environment
for item in &context.envlist() {
    println!("VAR: {}", item);
}

The environment can be passed to std::process::Command by using EnvList::iter_tuples():

use std::process::Command;

// Spawn a process in the PAM environment
let command = Command::new("/usr/bin/some_program")
                      .env_clear()
                      .envs(context.envlist().iter_tuples());

The environment can be passed to NIX’s execve by using EnvList::as_ref():

use nix::unistd::execve;

// Replace this process with another program in the PAM environment
execve(
    &CString::new("/usr/bin/some_program").unwrap(),
    &[CString::new("some_program").unwrap()],
    context.envlist().as_ref()
).expect("replacing the current process failed");

Implementations§

Source§

impl EnvList

Source

pub fn get<T: AsRef<OsStr>>(&self, name: T) -> Option<&OsStr>

Returns a reference to the value of the named environment variable.

Returns None if the variable doesn’t exist in this list.

Source

pub fn iter(&self) -> Iter<'_>

Returns an iterator over all contained variables as EnvItems.

The iteration happens in deterministic, but unspecified order.

Source

pub fn len(&self) -> usize

Returns the count of environment variables in the list.

Source

pub fn is_empty(&self) -> bool

Returns true if the environment list is empty.

Source

pub fn iter_tuples(&self) -> TupleIter<'_>

Returns an iterator over all contained variables as (key: &OsStr, value: &OsStr) tuples.

The iteration happens in deterministic, but unspecified order.

Provides compatibility with std::process::Command::envs().

Trait Implementations§

Source§

impl AsRef<[EnvItem]> for EnvList

Provide compatibility with the 3rd parameter of nix::unistd::execve.

Source§

fn as_ref(&self) -> &[EnvItem]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for EnvList

Source§

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

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

impl Display for EnvList

Display and string conversion of the environment list.

Also causes .to_string() to be implemented.

Source§

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

Formats the environment list as a multi-line string

Source§

impl<'a, S> From<&'a EnvList> for HashMap<&'a OsStr, &'a OsStr, S>
where S: BuildHasher + Default,

Reference conversion to a referencing hash map

Source§

fn from(list: &'a EnvList) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a EnvList> for Vec<&'a CStr>

Reference conversion to a vector of “key=value” &CStrs.

Source§

fn from(list: &'a EnvList) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a EnvList> for Vec<(&'a OsStr, &'a OsStr)>

Reference conversion to a vector of (&key, &value) tuples.

Source§

fn from(list: &'a EnvList) -> Self

Converts to this type from the input type.
Source§

impl<S> From<EnvList> for HashMap<OsString, OsString, S>
where S: BuildHasher + Default,

Conversion to a hash map

Source§

fn from(list: EnvList) -> Self

Converts to this type from the input type.
Source§

impl From<EnvList> for Vec<(OsString, OsString)>

Conversion to a vector of (key, value) tuples.

Source§

fn from(list: EnvList) -> Self

Converts to this type from the input type.
Source§

impl From<EnvList> for Vec<CString>

Conversion to a vector of “key=value” CStrings.

Source§

fn from(list: EnvList) -> Self

Converts to this type from the input type.
Source§

impl<T: AsRef<OsStr>> Index<T> for EnvList

Indexing with list[key]

Source§

fn index(&self, name: T) -> &Self::Output

Returns a reference to the value of the named environment variable.

§Panics

Panics if the environment variable is not present in the EnvList.

Source§

type Output = OsStr

The returned type after indexing.
Source§

impl<'a> IntoIterator for &'a EnvList

Provide direct for-loop support.

Source§

type Item = &'a EnvItem

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, EnvItem>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.