pub enum Value<'a> {
SingleLine(Option<Cow<'a, str>>),
MultiLine(Vec<Option<Cow<'a, str>>>),
}
Expand description
The value of an Attribute
.
Since only some values contain multiple lines and single line values do not require
additional heap allocation, an Enum is used to represent both variants.
Variants§
SingleLine(Option<Cow<'a, str>>)
A single line value.
§Example
let object = parse_object("
name: ACME Company
")?;
let value: Value = "ACME Company".parse()?;
assert_eq!(object[0].value, value);
MultiLine(Vec<Option<Cow<'a, str>>>)
A value spanning over multiple lines.
§Example
let object = parse_object("
remarks: Packet Street 6
128 Series of Tubes
Internet
")?;
let value: Value = vec!["Packet Street 6", "128 Series of Tubes", "Internet"].try_into()?;
assert_eq!(object[0].value, value);
Implementations§
Source§impl<'a> Value<'a>
impl<'a> Value<'a>
Sourcepub fn lines(&self) -> usize
pub fn lines(&self) -> usize
The number of lines contained.
§Examples
A value with a single line.
let value: Value = "ACME Company".parse()?;
assert_eq!(value.lines(), 1);
A value with multiple lines.
let value: Value = vec!["Packet Street 6", "128 Series of Tubes", "Internet"].try_into()?;
assert_eq!(value.lines(), 3);
Sourcepub fn with_content(&self) -> Vec<&str>
pub fn with_content(&self) -> Vec<&str>
The lines that contain content and are non empty.
§Example
let remarks = parse_object("
remarks: I have lots
to say.
")?;
assert_eq!(remarks[0].value.with_content(), vec!["I have lots", "to say."]);
Trait Implementations§
Source§impl FromStr for Value<'_>
impl FromStr for Value<'_>
Source§impl TryFrom<Vec<&str>> for Value<'_>
impl TryFrom<Vec<&str>> for Value<'_>
impl<'a> Eq for Value<'a>
impl<'a> StructuralPartialEq for Value<'a>
Auto Trait Implementations§
impl<'a> Freeze for Value<'a>
impl<'a> RefUnwindSafe for Value<'a>
impl<'a> Send for Value<'a>
impl<'a> Sync for Value<'a>
impl<'a> Unpin for Value<'a>
impl<'a> UnwindSafe for Value<'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