Skip to main content

Subst

Enum Subst 

Source
#[non_exhaustive]
pub enum Subst<'a> {
Show 25 variants Cmd(Vec<Cmd<'a>>), Arith(Option<Arith<'a>>), Len(Param<'a>), Indirect(&'a str), PrefixList(&'a str), Transform(&'a str, u8), Default(Param<'a>, Option<Word<'a>>), Assign(Param<'a>, Option<Word<'a>>), Error(Param<'a>, Option<Word<'a>>), Alt(Param<'a>, Option<Word<'a>>), TrimSuffixSmall(Param<'a>, Option<Word<'a>>), TrimSuffixLarge(Param<'a>, Option<Word<'a>>), TrimPrefixSmall(Param<'a>, Option<Word<'a>>), TrimPrefixLarge(Param<'a>, Option<Word<'a>>), Replace(Param<'a>, Option<Word<'a>>, Option<Word<'a>>), ReplaceAll(Param<'a>, Option<Word<'a>>, Option<Word<'a>>), ReplacePrefix(Param<'a>, Option<Word<'a>>, Option<Word<'a>>), ReplaceSuffix(Param<'a>, Option<Word<'a>>, Option<Word<'a>>), Substring(Param<'a>, &'a str, Option<&'a str>), Upper(bool, Param<'a>), Lower(bool, Param<'a>), ArrayElement(&'a str, Word<'a>), ArrayAll(&'a str), ArrayLen(&'a str), ArraySlice(&'a str, &'a str, Option<&'a str>),
}
Expand description

A substitution or parameter expansion.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Cmd(Vec<Cmd<'a>>)

Command substitution: $(cmd) or `cmd`.

§

Arith(Option<Arith<'a>>)

Arithmetic expansion: $((expr)).

§

Len(Param<'a>)

String length: ${#var}.

§

Indirect(&'a str)

${!var} — indirect variable expansion.

§

PrefixList(&'a str)

${!prefix*} / ${!prefix@} — list variables matching prefix.

§

Transform(&'a str, u8)

${var@Q} — parameter transformation (quoting).

§

Default(Param<'a>, Option<Word<'a>>)

${var:-word} / ${var-word} — default value.

§

Assign(Param<'a>, Option<Word<'a>>)

${var:=word} / ${var=word} — assign default.

§

Error(Param<'a>, Option<Word<'a>>)

${var:?word} / ${var?word} — error if unset.

§

Alt(Param<'a>, Option<Word<'a>>)

${var:+word} / ${var+word} — alternate value.

§

TrimSuffixSmall(Param<'a>, Option<Word<'a>>)

${var%pattern} — remove shortest suffix match.

§

TrimSuffixLarge(Param<'a>, Option<Word<'a>>)

${var%%pattern} — remove longest suffix match.

§

TrimPrefixSmall(Param<'a>, Option<Word<'a>>)

${var#pattern} — remove shortest prefix match.

§

TrimPrefixLarge(Param<'a>, Option<Word<'a>>)

${var##pattern} — remove longest prefix match.

§

Replace(Param<'a>, Option<Word<'a>>, Option<Word<'a>>)

${var/pattern/replacement} — replace first match.

§

ReplaceAll(Param<'a>, Option<Word<'a>>, Option<Word<'a>>)

${var//pattern/replacement} — replace all matches.

§

ReplacePrefix(Param<'a>, Option<Word<'a>>, Option<Word<'a>>)

${var/#pattern/replacement} — replace prefix match.

§

ReplaceSuffix(Param<'a>, Option<Word<'a>>, Option<Word<'a>>)

${var/%pattern/replacement} — replace suffix match.

§

Substring(Param<'a>, &'a str, Option<&'a str>)

${var:offset:length} — substring extraction.

§

Upper(bool, Param<'a>)

${var^} / ${var^^} — uppercase (bool: all if true).

§

Lower(bool, Param<'a>)

${var,} / ${var,,} — lowercase (bool: all if true).

§

ArrayElement(&'a str, Word<'a>)

${arr[index]} — array element access (index is a Word for $((expr)) support).

§

ArrayAll(&'a str)

${arr[@]} or ${arr[*]} — all array elements.

§

ArrayLen(&'a str)

${#arr[@]} — array length.

§

ArraySlice(&'a str, &'a str, Option<&'a str>)

${arr[@]:offset:length} — array slice.

Trait Implementations§

Source§

impl<'a> Clone for Subst<'a>

Source§

fn clone(&self) -> Subst<'a>

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> Debug for Subst<'a>

Source§

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

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

impl<'a> PartialEq for Subst<'a>

Source§

fn eq(&self, other: &Subst<'a>) -> 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<'a> Eq for Subst<'a>

Source§

impl<'a> StructuralPartialEq for Subst<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Subst<'a>

§

impl<'a> RefUnwindSafe for Subst<'a>

§

impl<'a> Send for Subst<'a>

§

impl<'a> Sync for Subst<'a>

§

impl<'a> Unpin for Subst<'a>

§

impl<'a> UnsafeUnpin for Subst<'a>

§

impl<'a> UnwindSafe for Subst<'a>

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.