pub enum Value {
Scalar(String),
Array(Vec<String>),
}Expand description
Value of a variable.
Variants§
Implementations§
Source§impl Value
impl Value
Sourcepub fn split(&self) -> impl Iterator<Item = &str>
pub fn split(&self) -> impl Iterator<Item = &str>
Splits the value by colons.
If this value is Scalar, the value is separated at each occurrence of
colon (:). For Array, each array item is returned without further
splitting the value.
let scalar = Value::scalar("/usr/local/bin:/usr/bin:/bin");
let values: Vec<&str> = scalar.split().collect();
assert_eq!(values, ["/usr/local/bin", "/usr/bin", "/bin"]);let array = Value::array(vec!["foo", "bar"]);
let values: Vec<&str> = array.split().collect();
assert_eq!(values, ["foo", "bar"]);Sourcepub fn quote(&self) -> QuotedValue<'_>
pub fn quote(&self) -> QuotedValue<'_>
Quotes the value in a format suitable for re-parsing.
This function returns a temporary wrapper of self. To obtain a string
representation of the quoted value, you can use the Display or
Into<Cow<str>> implementation for the returned object.
See yash_quote for details of quoting.
let scalar = Value::scalar("foo bar");
assert_eq!(scalar.quote().to_string(), "'foo bar'");
let array = Value::array(vec!["1", "", "'\\'"]);
assert_eq!(array.quote().to_string(), r#"(1 '' "'\\'")"#);Trait Implementations§
Source§impl AsRef<Value> for QuotedValue<'_>
Extracts the wrapped reference to the value.
impl AsRef<Value> for QuotedValue<'_>
Extracts the wrapped reference to the value.
Source§impl<'a> From<&'a Value> for QuotedValue<'a>
Wraps a value in QuotedValue.
impl<'a> From<&'a Value> for QuotedValue<'a>
Wraps a value in QuotedValue.
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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