pub enum StringValue<T: StringValueData> {
Raw(String),
Parsed(T),
}Expand description
A string value that can either be stored as a raw unparsed string or as a parsed value of type T.
The type T must implement the StringValueData trait, which defines how to parse and
serialize the value. This type is used whenever an EML_NL document element or attribute
contains a string value that could be parsed, but where strict parsing is not always desired.
Depending on the parsing mode used when parsing a document, StringValue
instances may either contain the raw string or the parsed value. When
EMLParsingMode::Strict is used, all
StringValue instances will contain the parsed value. When
EMLParsingMode::StrictFallback
is used, the library will attempt to parse values but will fall back to
storing the raw string if parsing fails. When
EMLParsingMode::Loose is used, the
library will not even attempt to parse values and will store all values as
raw strings.
In most cases you will want to use the parsed value by using one of the value retrieving methods:
StringValue::value: Get aCowcontaining either a borrowed reference to the parsed value or an owned parsed value if the StringValue contains a raw string. If the StringValue contains a raw string and parsing fails, the error from the parsing attempt will be returned as an error.StringValue::copied_value: Same asvalue, but only available for types that implementCopyand returns a copy of the value instead.StringValue::cloned_value: Same asvalue, but returns a cloned copy of the value instead of a reference. Only available for types that implementClone.
Variants§
Raw(String)
A raw unparsed string value that potentially can be parsed into a value of type T.
Parsed(T)
Parsed value of type T.
Implementations§
Source§impl<T: StringValueData> StringValue<T>
impl<T: StringValueData> StringValue<T>
Sourcepub fn from_raw_parsed(s: impl AsRef<str>) -> Result<Self, T::Error>
pub fn from_raw_parsed(s: impl AsRef<str>) -> Result<Self, T::Error>
Try to create a StringValue from the given raw string by parsing it.
Sourcepub fn from_raw(s: impl Into<String>) -> Self
pub fn from_raw(s: impl Into<String>) -> Self
Create a StringValue from a raw string.
Sourcepub fn from_value(v: T) -> Self
pub fn from_value(v: T) -> Self
Create a StringValue from a parsed value.
Sourcepub fn value_err(&self) -> Result<Cow<'_, T>, T::Error>
pub fn value_err(&self) -> Result<Cow<'_, T>, T::Error>
Get the parsed value, returning any possible parsing errors.
Sourcepub fn cloned_value_err(&self) -> Result<T, T::Error>
pub fn cloned_value_err(&self) -> Result<T, T::Error>
Get the parsed value, returning a cloned copy of it.
If there is an error, the original parsing error will be returned.
Sourcepub fn cloned_value(&self) -> Result<T, EMLError>
pub fn cloned_value(&self) -> Result<T, EMLError>
Get the parsed value, returning a cloned copy of it.
If there is an error, it will be wrapped in an EMLError.
Source§impl<T: StringValueData + Copy> StringValue<T>
impl<T: StringValueData + Copy> StringValue<T>
Sourcepub fn copied_value_err(&self) -> Result<T, T::Error>
pub fn copied_value_err(&self) -> Result<T, T::Error>
Get the parsed value, returning a copy of it.
This is only available for types that implement Copy.
Trait Implementations§
Source§impl<T: Clone + StringValueData> Clone for StringValue<T>
impl<T: Clone + StringValueData> Clone for StringValue<T>
Source§fn clone(&self) -> StringValue<T>
fn clone(&self) -> StringValue<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more