pub trait Expand {
// Required method
async fn expand(&self, env: &mut Env<'_>) -> Result<Phrase, Error>;
}Expand description
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Expand for TextUnit
Expands the text unit.
impl Expand for TextUnit
Expands the text unit.
Literalexpands to its character value.Backslashedexpands to two characters: a quoting backslash (\) followed by its quoted character value.RawParamandBracedParamperform parameter expansion, detailed below.CommandSubstandBackquoteperform command substitution: Thecontentstring is parsed and executed in a subshell where its standard output is redirected to a pipe read by the shell. The substitution expands to the output with trailing newlines removed.Arithperforms arithmetic expansion: The content text is expanded, parsing the result as an arithmetic expression. The evaluated value of the expression will be the final result of the expansion.
§Parameter expansion
A parameter expansion expands to the value of a parameter, optionally modified by a modifier.
The parameter name selects a parameter to expand. If the name is a positive decimal integer, it is regarded as a positional parameter. If the name matches one of the following special parameter symbols, that special parameter is expanded. Otherwise, the name selects a variable from the environment. A non-existent variable expands to an empty string by default.
?expands to the last exit status.!expands to the process ID of the last asynchronous command. If no asynchronous command has been executed (that is, if the value is zero), the parameter is considered unset.@expands to all positional parameters. When expanded in double-quotes as in"${@}", it produces the correct number of fields exactly matching the current positional parameters. Especially if there are zero positional parameters, it expands to zero fields.*expands to all positional parameters. When expanded in double-quotes as in"${*}", the result is a concatenation of all the positional parameters, each separated by the first character of theIFSvariable (or by a space if the variable is unset, or by nothing if it is an empty string). When expanded outside double-quotes,*expands the same as@.#expands to the number of positional parameters.-expands to a string that is a concatenation of the short names of options matching the current option states in the environment.$expands to the process ID of the main shell process (Env::main_pid). Note that this value does not change in subshells.0expands to the name of the current shell executable or shell script (Env::arg0).
TODO Elaborate on index and modifiers
Source§impl Expand for WordUnit
Expands the word unit.
impl Expand for WordUnit
Expands the word unit.
§Unquoted
Expansion of Unquoted(text_unit) delegates to expansion of text_unit.
§Single quote
SingleQuote(value) expands to value surrounded by '.
§Double quote
A double-quoted text expands to a phrase in a non-splitting context and
surrounds each field in the phrase with ".
§Dollar-single-quote
DollarSingleQuote(string) expands to
dollar_single_quote(&string.unquote().0) surrounded by $' and '.
§Tilde
Tilde("") expands to the value of the HOME scalar variable.
Tilde(user) expands to the user’s home directory.
TODO: ~+, ~-, ~+n, ~-n
In all cases, if the result would be empty, it expands to a dummy quote to prevent it from being removed in field splitting. The quote is expected to be removed by quote removal.
Source§impl<T: Expand> Expand for [T]
Expands a slice of expandable items.
impl<T: Expand> Expand for [T]
Expands a slice of expandable items.
This implementation is typically used for expanding a word or text. Each
item in the slice is recursively expanded, and the results are merged into
one phrase by Phrase::append.
If the slice has no item, the result is one empty field.