Struct bkt::CommandState

source ·
pub struct CommandState { /* private fields */ }
Expand description

The stateful sibling of CommandDesc which represents a command to be executed and cached along with environment state (e.g. the current working directory) at the time the CommandState instance is constructed. It consists of a command line invocation and application state determining how the command should be cached and executed. Additional with_* methods are provided on this type for further modifying how the subprocess will be executed.

Calling any of these methods changes how the invocation’s cache key will be constructed, therefore two invocations with different configured state will be cached separately, in the same manner as the with_* methods on CommandDesc.

§Examples

let cmd = bkt::CommandDesc::new(["echo", "Hello World!"]).capture_state();
let with_custom_wd = bkt::CommandDesc::new(["ls"]).capture_state()?.with_working_dir("/");
let with_env = bkt::CommandDesc::new(["date"]).capture_state()?.with_env("TZ", "UTC");

Implementations§

source§

impl CommandState

source

pub fn with_working_dir<P: AsRef<Path>>(self, cwd: P) -> Self

Sets the working directory the command should be run from, and causes this working directory to be included in the cache key. If unset the working directory will be inherited from the current process’ and will not be used to differentiate invocations in separate working directories.

let cmd = bkt::CommandDesc::new(["pwd"]);
let state = cmd.capture_state()?.with_working_dir("/tmp");
source

pub fn with_env<K, V>(self, key: K, value: V) -> Self
where K: AsRef<OsStr>, V: AsRef<OsStr>,

Adds the given key/value pair to the environment the command should be run from, and causes this pair to be included in the cache key.

let cmd = bkt::CommandDesc::new(["pwd"]);
let state = cmd.capture_state()?.with_env("FOO", "bar");
source

pub fn with_envs<I, K, V>(self, envs: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Adds the given key/value pairs to the environment the command should be run from, and causes these pair to be included in the cache key.

use std::env;
use std::collections::HashMap;

let important_envs : HashMap<String, String> =
    env::vars().filter(|&(ref k, _)|
        k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
    ).collect();
let cmd = bkt::CommandDesc::new(["..."]);
let state = cmd.capture_state()?.with_envs(&important_envs);

Trait Implementations§

source§

impl Clone for CommandState

source§

fn clone(&self) -> CommandState

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 CommandState

source§

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

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

impl<'de> Deserialize<'de> for CommandState

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<&CommandState> for Command

source§

fn from(cmd: &CommandState) -> Self

Converts to this type from the input type.
source§

impl Hash for CommandState

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for CommandState

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for CommandState

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
source§

impl TryFrom<&CommandDesc> for CommandState

§

type Error = Error

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

fn try_from(desc: &CommandDesc) -> Result<Self>

Performs the conversion.
source§

impl Eq for CommandState

source§

impl StructuralEq for CommandState

source§

impl StructuralPartialEq for CommandState

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,