Struct EnvironmentVariables

Source
pub struct EnvironmentVariables { /* private fields */ }
Expand description

The environment variables of WslGetDistributionConfiguration.

Implementations§

Source§

impl EnvironmentVariables

Source

pub fn new() -> Self

Create an empty/null array of environment variables

Source

pub fn len(&self) -> usize

Get the number of environment variables

Source

pub fn get(&self, index: usize) -> Option<(&[u8], &[u8])>

Get the key/value pair at index

Source

pub fn iter(&self) -> impl Iterator<Item = (&[u8], &[u8])>

Iterate over the key/value pairs

Examples found in repository?
examples/basic.rs (line 20)
5fn main() {
6    let ubuntu = "Ubuntu";
7    let nonexistant = "Nonexistant";
8
9    let wsl = Library::new().unwrap();
10    assert!( wsl.is_distribution_registered(ubuntu));
11    assert!(!wsl.is_distribution_registered(nonexistant));
12    assert!(wsl.get_distribution_configuration(nonexistant).is_err());
13
14    let cfg = wsl.get_distribution_configuration(ubuntu).unwrap();
15    assert!(cfg.default_uid == 0 || (1000 ..= 2000).contains(&cfg.default_uid)); // Root or regular UID
16    assert!(cfg.flags & WSL_DISTRIBUTION_FLAGS::DEFAULT == WSL_DISTRIBUTION_FLAGS::DEFAULT);
17    assert!((1..=2).contains(&cfg.version)); // WSL version
18
19    println!("Environment varibales:");
20    for (k,v) in cfg.default_environment_variables.iter() {
21        // XXX: This might be inaccurate / depend on the linux locale?  Good enough for a demo though!
22        let k = String::from_utf8_lossy(k);
23        let v = String::from_utf8_lossy(v);
24        println!("{: <10} = {}", k, v);
25    }
26
27    wsl.launch_interactive(ubuntu, "echo testing 123", true).unwrap();
28
29    let stdin  = "echo testing 456\necho PATH: ${PATH}\nasdf";
30    let stdout = std::fs::File::create("target/basic.txt").unwrap();
31    let stderr = std::fs::File::create("CON").unwrap();
32    wsl.launch(ubuntu, "sh", true, stdin, stdout, stderr).unwrap().wait().unwrap();
33
34    println!("\rPress ENTER to quit");
35    let _ = std::io::stdin().read_line(&mut String::new());
36}

Trait Implementations§

Source§

impl Default for EnvironmentVariables

Source§

fn default() -> Self

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

impl Drop for EnvironmentVariables

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'e> IntoIterator for &'e EnvironmentVariables

Source§

type Item = (&'e [u8], &'e [u8])

The type of the elements being iterated over.
Source§

type IntoIter = EnvironmentVariablesIter<'e>

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, 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.