Skip to main content

Launcher

Struct Launcher 

Source
pub struct Launcher {
    pub prefix: Vec<OsString>,
    pub cwd: Option<PathBuf>,
    pub env: Vec<(OsString, OsString)>,
    pub unset_env: Vec<OsString>,
}
Expand description

How tools start processes: under a wrapper program (a sandbox such as bwrap … --, nice -n 10, a container’s exec), in a directory, with variables set and removed. Every command it builds is detached. A host that hands one launcher to every tool that starts processes (Shell, a background job, a formatter) puts them all under the same policy.

use rig_tools::process::Launcher;

let launcher = Launcher::default()
    .wrapped(["nice", "-n", "10"])
    .in_dir("/srv/project")
    .with_env("CI", "1")
    .without_env(["AGENT_TOKEN"]);
let mut command = launcher.command("sh");
command.args(["-c", "make test"]);
assert_eq!(command.get_program(), "nice");
let args: Vec<_> = command.get_args().collect();
assert_eq!(args, ["-n", "10", "sh", "-c", "make test"]);
assert_eq!(command.get_current_dir(), Some(std::path::Path::new("/srv/project")));

Fields§

§prefix: Vec<OsString>

The program and arguments every command runs under; empty runs the command itself.

§cwd: Option<PathBuf>

The directory commands start in; None is this process’s.

§env: Vec<(OsString, OsString)>

Variables set for every command.

§unset_env: Vec<OsString>

Variables no command inherits, such as those that make a program act as the agent that runs it.

Implementations§

Source§

impl Launcher

Source

pub fn wrapped( self, prefix: impl IntoIterator<Item = impl Into<OsString>>, ) -> Self

The same launcher, running every command under prefix.

Source

pub fn in_dir(self, dir: impl Into<PathBuf>) -> Self

The same launcher, starting commands in dir.

Source

pub fn with_env( self, name: impl Into<OsString>, value: impl Into<OsString>, ) -> Self

The same launcher, setting name to value for every command.

Source

pub fn without_env( self, names: impl IntoIterator<Item = impl Into<OsString>>, ) -> Self

The same launcher, keeping names from every command.

Source

pub fn command(&self, program: impl AsRef<OsStr>) -> Command

A detached command that runs program under this launcher’s policy; add the program’s arguments to it.

Source

pub fn spawn( &self, program: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>, how: Spawn, ) -> Result<Process>

Starts program with args under this launcher’s policy, as command builds it, with stdin and output as how says.

use rig_tools::process::{Launcher, OutputLine, Spawn};

let how = Spawn { stdin: Some(b"hello\n".to_vec()), ..Spawn::default() };
let mut process = Launcher::default().spawn("cat", ["-"], how)?;
let status = process.wait_for(std::time::Duration::from_secs(5))?;
assert!(status.is_some_and(|status| status.success()));
let lines: Vec<OutputLine> = process.lines().iter().collect();
assert_eq!(lines, [OutputLine::Out("hello\n".to_owned())]);

Trait Implementations§

Source§

impl Clone for Launcher

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Launcher

Source§

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

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

impl Default for Launcher

Source§

fn default() -> Self

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

impl Eq for Launcher

Source§

impl PartialEq for Launcher

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Launcher

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more