Struct envvars::Profile

source ·
pub struct Profile {
    pub name: String,
    pub path: PathBuf,
    pub envvars: Option<HashMap<String, String>>,
    pub symlink: bool,
    /* private fields */
}
Expand description

Definition of shell profile

Fields§

§name: String

Suggested name of shell. For unix based systems it will be name of executable file, like “bash”, “fish” etc. For windows it will be names like “GitBash”, “PowerShell” etc.

§path: PathBuf

Path to executable file of shell

§envvars: Option<HashMap<String, String>>

List of environment variables. Because extracting operation could take some time by default envvars = None. To load data should be used method load, which will make attempt to detect environment variables.

§symlink: bool

true - if path to executable file of shell is symlink to another location.

Implementations§

source§

impl Profile

source

pub fn new( shell: &PathBuf, args: Vec<&str>, name: Option<&str> ) -> Result<Self, Error>

Creates shell’s profile description

  • shell - path to shell’s executable file
  • args - list of arguments needed to pass a command into shell. For example: “-c” to have a full command like: “/etc/bin/bash -c cmd”
  • name - optional name for profile. For unix based systems it will be name of executable file, like “bash”, “fish” etc. For windows better to provide name to have it like “GitBash”, “PowerShell” etc.
source

pub fn load(&mut self) -> Result<(), Error>

Makes attempt to grab a list of environment variables for profile. It will spawn an instance of shell with extractor as command argument. If stdout will have suitable output, it will be parsed and list of environment variables will be saved in self.envvars

§Examples
use std::{path::PathBuf, str::FromStr};
use envvars::Profile;

let mut profile: Profile = if cfg!(windows) {
    Profile::new(&PathBuf::from_str("C:\\Program Files\\Git\\bin\\bash.exe").unwrap(), vec!["-c"], None).unwrap()
} else {
    Profile::new(&PathBuf::from_str("/bin/bash").unwrap(), vec!["-c"], None).unwrap()
};

assert_eq!(profile.name, if cfg!(windows) {
    "bash.exe"
} else {
    "bash"
});

profile.load().unwrap();

assert!(profile.envvars.is_some());

if let Some(vars) = profile.envvars.as_ref() {
    assert!(vars.contains_key("PATH") || vars.contains_key("Path") || vars.contains_key("path"));
}

Trait Implementations§

source§

impl Clone for Profile

source§

fn clone(&self) -> Profile

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Profile

source§

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

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

impl Serialize for Profile

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.