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<'_>
impl AsRef<Value> for QuotedValue<'_>
Extracts the wrapped reference to the value.
source§impl<'a> From<&'a Value> for QuotedValue<'a>
impl<'a> From<&'a Value> for QuotedValue<'a>
Wraps a value in QuotedValue.
source§impl PartialEq for Value
impl PartialEq for Value
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)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