pub enum Value<'a, Spec: Specification = Raw> {
SingleLine {
inner: Option<Cow<'a, str>>,
_spec: PhantomData<Spec>,
},
MultiLine {
inner: Vec<Option<Cow<'a, str>>>,
_spec: PhantomData<Spec>,
},
}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
A single line value.
§Example
let object = parse_object("
name: ACME Company
")?;
let value = Value::new_single("ACME Company");
assert_eq!(object[0].value, value);MultiLine
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"].into();
assert_eq!(object[0].value, value);Implementations§
Source§impl<'a, Spec: Specification> Value<'a, Spec>
impl<'a, Spec: Specification> Value<'a, Spec>
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::new_single("ACME Company");
assert_eq!(value.lines(), 1);A value with multiple lines.
let value: Value = vec!["Packet Street 6", "128 Series of Tubes", "Internet"].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."]);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the value is empty.
§Example
let remarks = parse_object("
remarks:
")?;
assert_eq!(remarks[0].value.is_empty(), true);Sourcepub fn into_owned(self) -> Value<'static, Spec>
pub fn into_owned(self) -> Value<'static, Spec>
Convert this value into an owned ('static) version.
Trait Implementations§
Source§impl<'a, Spec: Specification> Serialize for Value<'a, Spec>
impl<'a, Spec: Specification> Serialize for Value<'a, Spec>
impl<'a, Spec: Eq + Specification> Eq for Value<'a, Spec>
impl<'a, Spec: Specification> StructuralPartialEq for Value<'a, Spec>
Auto Trait Implementations§
impl<'a, Spec> Freeze for Value<'a, Spec>
impl<'a, Spec> RefUnwindSafe for Value<'a, Spec>where
Spec: RefUnwindSafe,
impl<'a, Spec> Send for Value<'a, Spec>where
Spec: Send,
impl<'a, Spec> Sync for Value<'a, Spec>where
Spec: Sync,
impl<'a, Spec> Unpin for Value<'a, Spec>where
Spec: Unpin,
impl<'a, Spec> UnwindSafe for Value<'a, Spec>where
Spec: UnwindSafe,
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