pub enum Expansion<'a> {
Unset,
Scalar(Cow<'a, str>),
Array(Cow<'a, [String]>),
}Expand description
Expanded value of a variable
Variables with a Quirk may have their values computed dynamically when
expanded, hence Cow in the enum values.
Use Variable::expand to get an Expansion instance.
Variants§
Unset
The value does not exist.
Scalar(Cow<'a, str>)
The value is a single string.
Array(Cow<'a, [String]>)
The value is an array of strings.
Implementations§
Source§impl Expansion<'_>
impl Expansion<'_>
Sourcepub fn into_owned(self) -> Option<Value>
pub fn into_owned(self) -> Option<Value>
Converts into an owned value
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the “length” of the value.
For Unset, the length is 0.
For Scalar, the length is the number of characters.
For Array, the length is the number of strings.
Sourcepub fn split(&self) -> impl Iterator<Item = &str>
pub fn split(&self) -> impl Iterator<Item = &str>
Splits the expansion by colons.
If this expansion is Scalar, the value is separated at each occurrence
of colon (:). For Array, each array item is returned without further
splitting the value. For Unset, an empty iterator is returned.
let expansion = Expansion::from("/usr/local/bin:/usr/bin:/bin");
let values: Vec<&str> = expansion.split().collect();
assert_eq!(values, ["/usr/local/bin", "/usr/bin", "/bin"]);let expansion = Expansion::from(vec!["foo".to_string(), "bar".to_string()]);
let values: Vec<&str> = expansion.split().collect();
assert_eq!(values, ["foo", "bar"]);let expansion = Expansion::Unset;
let values: Vec<&str> = expansion.split().collect();
assert!(values.is_empty());Trait Implementations§
impl<'a> Eq for Expansion<'a>
impl<'a> StructuralPartialEq for Expansion<'a>
Auto Trait Implementations§
impl<'a> Freeze for Expansion<'a>
impl<'a> RefUnwindSafe for Expansion<'a>
impl<'a> Send for Expansion<'a>
impl<'a> Sync for Expansion<'a>
impl<'a> Unpin for Expansion<'a>
impl<'a> UnwindSafe for Expansion<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more