Env

Struct Env 

Source
pub struct Env<A, FM, L, V, EX, WD, B, N: Eq + Hash, ERR> { /* private fields */ }
Expand description

A shell environment implementation which delegates work to other environment implementations.

Implementations§

Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> Env<A, FM, L, V, EX, WD, B, N, ERR>
where N: Hash + Eq,

Source

pub fn with_config(cfg: EnvConfig<A, FM, L, V, EX, WD, B, N, ERR>) -> Self

Creates an environment using the provided configuration of subcomponents.

See EnvConfig for the kinds of overrides possible. DefaultEnvConfig comes with provided implementations to get you up and running.

General recommendations:

  • The result of evaluating a shell word will often be copied and reused in many different places. It’s strongly recommened that an Arc wrapper (e.g. Arc<String>) is used to minimize having to reallocate and copy the same data.
  • Whatever type represents a shell function body needs to be cloned to get around borrow restrictions and potential recursive executions and (re-)definitions. Since this type is probably an AST (which may be arbitrarily large), Arc is your friend.
Source§

impl<T> Env<ArgsEnv<T>, TokioFileDescManagerEnv, LastStatusEnv, VarEnv<T, T>, TokioExecEnv, VirtualWorkingDirEnv, BuiltinEnv<T>, T, RuntimeError>
where T: StringWrapper,

Source

pub fn new() -> Result<Self>

Creates a new default environment.

See the definition of DefaultEnvConfig for what configuration will be used.

Trait Implementations§

Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> ArgumentsEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where A: ArgumentsEnvironment, A::Arg: Clone, N: Hash + Eq,

Source§

type Arg = <A as ArgumentsEnvironment>::Arg

The type of arguments this environment holds.
Source§

fn name(&self) -> &Self::Arg

Get the name of the shell.
Source§

fn arg(&self, idx: usize) -> Option<&Self::Arg>

Get an argument at any index. Arguments are 1-indexed since the shell variable $0 refers to the shell’s name. Thus the first real argument starts at index 1.
Source§

fn args_len(&self) -> usize

Get the number of current arguments, NOT including the shell name.
Source§

fn args(&self) -> Cow<'_, [Self::Arg]>

Get all current arguments as a possibly owned slice.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> AsyncIoEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where FM: AsyncIoEnvironment, N: Hash + Eq,

Source§

type IoHandle = <FM as AsyncIoEnvironment>::IoHandle

The underlying handle (e.g. FileDesc) with which to perform the async I/O.
Source§

fn read_all( &mut self, fd: Self::IoHandle, ) -> BoxFuture<'static, Result<Vec<u8>>>

Asynchronously read all data from the specified handle.
Source§

fn write_all<'a>( &mut self, fd: Self::IoHandle, data: Cow<'a, [u8]>, ) -> BoxFuture<'a, Result<()>>

Asynchronously write data into the specified handle.
Source§

fn write_all_best_effort(&mut self, fd: Self::IoHandle, data: Vec<u8>)

Asynchronously write the contents of data to a file handle in the background on a best effort basis (e.g. the implementation can give up due to any (appropriately) unforceen errors like broken pipes).
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> BuiltinEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where N: Hash + Eq, B: BuiltinEnvironment,

Source§

type BuiltinName = <B as BuiltinEnvironment>::BuiltinName

The name for looking up a builtin utility.
Source§

type Builtin = <B as BuiltinEnvironment>::Builtin

The type of the builtin utility.
Source§

fn builtin(&self, name: &Self::BuiltinName) -> Option<Self::Builtin>

Lookup and get a particular builtin by its name.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> ChangeWorkingDirectoryEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn change_working_dir<'a>(&mut self, path: Cow<'a, Path>) -> Result<()>

Changes the environment’s current working directory to the following path. Read more
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> Clone for Env<A, FM, L, V, EX, WD, B, N, ERR>
where A: Clone, FM: Clone, L: Clone, V: Clone, B: Clone, N: Hash + Eq, EX: Clone, WD: Clone,

Source§

fn clone(&self) -> Self

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<A, FM, L, V, EX, WD, B, N, ERR> Debug for Env<A, FM, L, V, EX, WD, B, N, ERR>
where A: Debug, FM: Debug, L: Debug, V: Debug, B: Debug, N: Hash + Eq + Ord + Debug, EX: Debug, WD: Debug,

Source§

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

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

impl<A, FM, L, V, EX, WD, B, N, ERR> ExecutableEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where N: Hash + Eq, EX: ExecutableEnvironment,

Source§

fn spawn_executable( &self, data: ExecutableData<'_>, ) -> Result<BoxFuture<'static, ExitStatus>, CommandError>

Attempt to spawn the executable command.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> ExportedVariableEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn exported_var(&self, name: &Self::VarName) -> Option<(&Self::Var, bool)>

Get the value of some variable and whether it is exported.
Source§

fn set_exported_var( &mut self, name: Self::VarName, val: Self::Var, exported: bool, )

Set the value of some variable, and set it’s exported status as specified.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> FileDescEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where FM: FileDescEnvironment, N: Hash + Eq,

Source§

type FileHandle = <FM as FileDescEnvironment>::FileHandle

A file handle (or wrapper) to associate with shell file descriptors.
Source§

fn file_desc(&self, fd: Fd) -> Option<(&Self::FileHandle, Permissions)>

Get the permissions and a handle associated with an opened file descriptor.
Source§

fn set_file_desc(&mut self, fd: Fd, fdes: Self::FileHandle, perms: Permissions)

Associate a file descriptor with a given handle and permissions.
Source§

fn close_file_desc(&mut self, fd: Fd)

Treat the specified file descriptor as closed for the current environment.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> FileDescOpener for Env<A, FM, L, V, EX, WD, B, N, ERR>
where FM: FileDescOpener, N: Hash + Eq,

Source§

type OpenedFileHandle = <FM as FileDescOpener>::OpenedFileHandle

A type which represents an opened file descriptor.
Source§

fn open_path( &mut self, path: &Path, opts: &OpenOptions, ) -> Result<Self::OpenedFileHandle>

Open a provided path with the specified OpenOptions.
Source§

fn open_pipe(&mut self) -> Result<Pipe<Self::OpenedFileHandle>>

Create a new Pipe pair.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> From<EnvConfig<A, FM, L, V, EX, WD, B, N, ERR>> for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn from(cfg: EnvConfig<A, FM, L, V, EX, WD, B, N, ERR>) -> Self

Converts to this type from the input type.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> FunctionEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where N: Hash + Eq + Clone,

Source§

type FnName = N

The name to be associated with a function.
Source§

type Fn = Arc<dyn Spawn<Env<A, FM, L, V, EX, WD, B, N, ERR>, Error = ERR> + Send + Sync>

The type of the function.
Source§

fn function(&self, name: &Self::FnName) -> Option<&Self::Fn>

Get a particularly named function if it was registered.
Source§

fn set_function(&mut self, name: Self::FnName, func: Self::Fn)

Register a shell function with a given name.
Source§

fn has_function(&self, name: &Self::FnName) -> bool

Check if a particularly named function was registered.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> FunctionFrameEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where N: Hash + Eq + Clone,

Source§

fn push_fn_frame(&mut self)

Denote that a new function has been invoked and is currently executing.
Source§

fn pop_fn_frame(&mut self)

Denote that a function has completed and is no longer executing.
Source§

fn is_fn_running(&self) -> bool

Determines if there is at least one function being currently executed.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> IsInteractiveEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where N: Hash + Eq,

Source§

fn is_interactive(&self) -> bool

Indicates if running in interactive mode.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> LastStatusEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where L: LastStatusEnvironment, N: Hash + Eq,

Source§

fn last_status(&self) -> ExitStatus

Get the exit status of the previous command.
Source§

fn set_last_status(&mut self, status: ExitStatus)

Set the exit status of the previously run command.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> ReportErrorEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn report_error<'a>( &mut self, fail: &'a (dyn Error + Sync + Send + 'static), ) -> BoxFuture<'a, ()>

Reports any Error as appropriate, e.g. print to stderr.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> SetArgumentsEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

type Args = <A as SetArgumentsEnvironment>::Args

A collection of arguments to set.
Source§

fn set_args(&mut self, new_args: Self::Args) -> Self::Args

Changes the environment’s arguments to new_args and returns the old arguments.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> ShiftArgumentsEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn shift_args(&mut self, amt: usize)

Shift parameters such that the positional parameter n will hold the value of the positional parameter n + amt. Read more
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> SubEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn sub_env(&self) -> Self

Create a new sub-environment, which starts out idential to its parent, but any changes on the new environment will not be reflected on the parent.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> UnsetFunctionEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where N: Hash + Eq + Clone,

Source§

fn unset_function(&mut self, name: &Self::FnName)

Removes the definition of a function if it was registered.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> UnsetVariableEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn unset_var(&mut self, name: &V::VarName)

Unset the value of some variable (including environment variables).
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> VariableEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>
where V: VariableEnvironment, N: Hash + Eq,

Source§

type VarName = <V as VariableEnvironment>::VarName

The type of the name this environment associates for a variable.
Source§

type Var = <V as VariableEnvironment>::Var

The type of variables this environment holds.
Source§

fn var<Q>(&self, name: &Q) -> Option<&Self::Var>
where Self::VarName: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get the value of some variable. The values of both shell-only and environment variables will be looked up and returned.
Source§

fn set_var(&mut self, name: Self::VarName, val: Self::Var)

Set the value of some variable, maintaining its status as an environment variable if previously set as such.
Source§

fn env_vars(&self) -> Cow<'_, [(&Self::VarName, &Self::Var)]>

Unset the value of some variable (including environment variables). Get all current pairs of environment variables and their values.
Source§

impl<A, FM, L, V, EX, WD, B, N, ERR> WorkingDirectoryEnvironment for Env<A, FM, L, V, EX, WD, B, N, ERR>

Source§

fn path_relative_to_working_dir<'a>(&self, path: Cow<'a, Path>) -> Cow<'a, Path>

Converts the specified path to one relative to the environment’s working directory.
Source§

fn current_working_dir(&self) -> &Path

Retrieves the current working directory of this environment.

Auto Trait Implementations§

§

impl<A, FM, L, V, EX, WD, B, N, ERR> Freeze for Env<A, FM, L, V, EX, WD, B, N, ERR>
where A: Freeze, FM: Freeze, L: Freeze, V: Freeze, EX: Freeze, WD: Freeze, B: Freeze,

§

impl<A, FM, L, V, EX, WD, B, N, ERR> !RefUnwindSafe for Env<A, FM, L, V, EX, WD, B, N, ERR>

§

impl<A, FM, L, V, EX, WD, B, N, ERR> Send for Env<A, FM, L, V, EX, WD, B, N, ERR>
where A: Send, FM: Send, L: Send, V: Send, EX: Send, WD: Send, B: Send, N: Sync + Send,

§

impl<A, FM, L, V, EX, WD, B, N, ERR> Sync for Env<A, FM, L, V, EX, WD, B, N, ERR>
where A: Sync, FM: Sync, L: Sync, V: Sync, EX: Sync, WD: Sync, B: Sync, N: Sync + Send,

§

impl<A, FM, L, V, EX, WD, B, N, ERR> Unpin for Env<A, FM, L, V, EX, WD, B, N, ERR>
where A: Unpin, FM: Unpin, L: Unpin, V: Unpin, EX: Unpin, WD: Unpin, B: Unpin,

§

impl<A, FM, L, V, EX, WD, B, N, ERR> !UnwindSafe for Env<A, FM, L, V, EX, WD, B, N, ERR>

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<T> FileDescManagerEnvironment for T