Struct procspawn::Builder

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

Process factory, which can be used in order to configure the properties of a process being created.

Methods can be chained on it in order to configure it.

Implementations§

source§

impl Builder

source

pub fn new() -> Self

Generates the base configuration for spawning a thread, from which configuration methods can be chained.

Examples found in repository?
examples/stdout.rs (line 7)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    procspawn::init();

    let mut builder = procspawn::Builder::new();
    builder.stdout(Stdio::piped());

    let mut handle = builder.spawn((1, 2), |(a, b)| {
        println!("{:?} {:?}", a, b);
    });

    let mut s = String::new();
    handle.stdout().unwrap().read_to_string(&mut s).unwrap();
    assert_eq!(s, "1 2\n");
}
source

pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Selfwhere K: AsRef<OsStr>, V: AsRef<OsStr>,

Set an environment variable in the spawned process.

Equivalent to Command::env

source

pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Selfwhere I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Set environment variables in the spawned process.

Equivalent to Command::envs

source

pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self

Removes an environment variable in the spawned process.

Equivalent to Command::env_remove

source

pub fn env_clear(&mut self) -> &mut Self

Clears all environment variables in the spawned process.

Equivalent to Command::env_clear

source

pub fn uid(&mut self, id: u32) -> &mut Self

Sets the child process’s user ID. This translates to a setuid call in the child process. Failure in the setuid call will cause the spawn to fail.

Unix-specific extension only available on unix.

Equivalent to std::os::unix::process::CommandExt::uid

source

pub fn gid(&mut self, id: u32) -> &mut Self

Similar to uid, but sets the group ID of the child process. This has the same semantics as the uid field.

Unix-specific extension only available on unix.

Equivalent to std::os::unix::process::CommandExt::gid

source

pub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Selfwhere F: FnMut() -> Result<()> + Send + Sync + 'static,

Schedules a closure to be run just before the exec function is invoked.

Safety

This method is inherently unsafe. See the notes of the unix command ext for more information.

Equivalent to std::os::unix::process::CommandExt::pre_exec

source

pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Captures the stdin of the spawned process, allowing you to manually send data via JoinHandle::stdin

source

pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Captures the stdout of the spawned process, allowing you to manually receive data via JoinHandle::stdout

Examples found in repository?
examples/stdout.rs (line 8)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    procspawn::init();

    let mut builder = procspawn::Builder::new();
    builder.stdout(Stdio::piped());

    let mut handle = builder.spawn((1, 2), |(a, b)| {
        println!("{:?} {:?}", a, b);
    });

    let mut s = String::new();
    handle.stdout().unwrap().read_to_string(&mut s).unwrap();
    assert_eq!(s, "1 2\n");
}
source

pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Captures the stderr of the spawned process, allowing you to manually receive data via JoinHandle::stderr

source

pub fn spawn<A: Serialize + DeserializeOwned, R: Serialize + DeserializeOwned>( &mut self, args: A, func: fn(_: A) -> R ) -> JoinHandle<R>

Spawns the process.

Examples found in repository?
examples/stdout.rs (lines 10-12)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    procspawn::init();

    let mut builder = procspawn::Builder::new();
    builder.stdout(Stdio::piped());

    let mut handle = builder.spawn((1, 2), |(a, b)| {
        println!("{:?} {:?}", a, b);
    });

    let mut s = String::new();
    handle.stdout().unwrap().read_to_string(&mut s).unwrap();
    assert_eq!(s, "1 2\n");
}

Trait Implementations§

source§

impl Debug for Builder

source§

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

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

impl Default for Builder

source§

fn default() -> Builder

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V