CmdOptions

Struct CmdOptions 

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

CmdOptions are used to describe command’s additional settings.

It allows to configure command’s input/outputs, working_directory and environment variables.

Command’s input allows to send messages from parent process, and receive them in spawned (child) process. Whereas the message output of the command is used for communication in the opposite direction. Communication with a process can be done using standard I/O or named pipes.

It is also possible to set logging in order to allow child process to produce logs which, unlike messages, are stored permanently and therefore can be read multiple times by parent process.

Implementations§

Source§

impl CmdOptions

Source

pub fn with_standard_io_messaging() -> CmdOptions

Create options with configured messaging input/output via standard I/O.

Source

pub fn with_named_pipe_messaging() -> CmdOptions

Create options with configured messaging input/output via named pipes.

Source

pub fn with_message_input(message_input: MessagingType) -> Self

Create options with configured messaging input type.

Source

pub fn with_message_output(message_output: MessagingType) -> Self

Create options with configured messaging output type.

Source

pub fn with_logging(logging_type: LoggingType) -> Self

Create options with configured logging type.

Source

pub fn set_current_dir(&mut self, dir: PathBuf)

Set process’s working directory.

Source

pub fn clear_inherited_envs(&mut self, value: bool)

By default, child process will inherit all environment variables from the parent. To prevent this behavior set this value to true.

Source

pub fn set_envs<K, V, I>(&mut self, envs: I)
where K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>,

Set environment variables for a process.

§Examples
let mut envs = HashMap::new();
envs.insert("TEST_ENV_VAR_1", "value1");
envs.insert("TEST_ENV_VAR_2", "value2");

let mut options = CmdOptions::default();
options.set_envs(envs);
Source

pub fn add_env<K, V>(&mut self, name: K, value: V)
where K: Into<String>, V: Into<String>,

Add or update single environment variable.

Source

pub fn remove_env<S>(&mut self, name: S)
where S: Into<String> + AsRef<str>,

Remove single environment variable (manually set earlier and also inherited from the parent process).

Source

pub fn set_message_input(&mut self, messaging_type: MessagingType)

Set message input type.

Source

pub fn set_message_output( &mut self, messaging_type: MessagingType, ) -> Result<(), CmdOptionsError>

Set message output type.

This method will return CmdOptionsError::StdoutConfigurationConflict when trying to set MessagingType::StandardIo and logging to stdout was previously configured.

Source

pub fn set_logging_type( &mut self, logging_type: LoggingType, ) -> Result<(), CmdOptionsError>

Set logging type.

This method will return CmdOptionsError::StdoutConfigurationConflict when trying to set logging to stdout and message output was previously configured as MessagingType::StandardIo.

Source

pub fn set_message_output_buffer_capacity(&mut self, capacity: BufferCapacity)

Set message output buffer capacity for receiving end (parent process).

When parent process is not reading messages produced by a child process, then the messages are buffered up to the given capacity value. If the buffer limit is reached and a child process sends a new message, the “oldest” buffered message will be removed.

Source

pub fn current_dir(&self) -> Option<&PathBuf>

Get current directory.

Source

pub fn inherited_envs_cleared(&self) -> bool

Check if inherited environment variables will be cleared.

Source

pub fn envs(&self) -> &HashMap<String, String>

Get environment variables.

Source

pub fn inherited_envs_to_remove(&self) -> &[String]

Get inherited environment variables to remove.

Source

pub fn message_input(&self) -> Option<&MessagingType>

Get message input type.

Source

pub fn message_output(&self) -> Option<&MessagingType>

Get message output type.

Source

pub fn logging_type(&self) -> Option<&LoggingType>

Get logging type.

Source

pub fn message_output_buffer_capacity(&self) -> &BufferCapacity

Get message output buffer capacity.

Source

pub fn update(&mut self, other: CmdOptions)

Update this options using values of other CmdOptions.

§Examples
let mut options = CmdOptions::default();
let mut other = CmdOptions::with_standard_io_messaging();
other.clear_inherited_envs(true);

options.update(other);

let expected = MessagingType::StandardIo;
assert!(matches!(options.message_input(), expected));
assert!(matches!(options.message_output(), expected));
assert!(options.inherited_envs_cleared());

Trait Implementations§

Source§

impl Clone for CmdOptions

Source§

fn clone(&self) -> CmdOptions

Returns a duplicate 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 CmdOptions

Source§

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

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

impl Default for CmdOptions

Source§

fn default() -> CmdOptions

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

impl<'de> Deserialize<'de> for CmdOptions

Available on crate feature serde only.
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 PartialEq for CmdOptions

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CmdOptions

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 Eq for CmdOptions

Source§

impl StructuralPartialEq for CmdOptions

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

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

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

Source§

fn vzip(self) -> V

Source§

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