pub enum CharacterData {
Enum(EnumItem),
String(String),
UnsignedInteger(u64),
Float(f64),
}Expand description
The enum CharacterData provides typed access to the content of elements and attributes
Example:
In the xml string <SHORT-NAME>SomeName</SHORT-NAME> the character data
“SomeName” will be loaded as CharacterData::String("SomeName“), while the content of the
attribute <… DEST=“UNIT”> will be loaded as CharacterData::Enum(EnumItem::Unit)
Variants§
Enum(EnumItem)
Character data is an enum value
String(String)
Character data is a string
UnsignedInteger(u64)
Character data is an unsigned integer
Float(f64)
Character data is a floating point number
Implementations§
Source§impl CharacterData
impl CharacterData
Sourcepub fn enum_value(&self) -> Option<EnumItem>
pub fn enum_value(&self) -> Option<EnumItem>
Get the contained enum value
Returns the enum value if the content is an enum, or None otherwise
Sourcepub fn string_value(&self) -> Option<String>
pub fn string_value(&self) -> Option<String>
Get the contained string
Returns the string if the content is a string, or None otherwise
Sourcepub fn unsigned_integer_value(&self) -> Option<u64>
pub fn unsigned_integer_value(&self) -> Option<u64>
Get the contained unsigned integer
Returns the string if the content is a string, or None otherwise
Sourcepub fn float_value(&self) -> Option<f64>
pub fn float_value(&self) -> Option<f64>
Get the contained floating point value
Returns the value if the content is a float, or None otherwise
Sourcepub fn parse_integer<T: Num + TryFrom<u64>>(&self) -> Option<T>
pub fn parse_integer<T: Num + TryFrom<u64>>(&self) -> Option<T>
parse the stored charcter data value as an integer
Many numbers are stored as strings in order to allow hexadecimal, octal, and binary encoding. This function handles the conversion from text to integer. If the stored value is already an integer, it will be converted to the output type.
Returns the value if the conversion succeeds, or None otherwise
§Example
let data = CharacterData::String("0x1234".to_string());
let value = data.parse_integer::<u32>().unwrap();
assert_eq!(value, 0x1234);Sourcepub fn parse_float(&self) -> Option<f64>
pub fn parse_float(&self) -> Option<f64>
parse the stored character data value as a floating point number
When the meta model declares that a value is of class “Numerical”, this means it is stored as a string. The regex associated with “Numerical” allows signed integers, floating point values (including scientific notation, as well as INF and NaN), hexadecimal, octal, and binary numbers. This function handles the conversion from text to floating point.
Returns the value if the conversion succeeds, or None otherwise
§Example
let data = CharacterData::String("0x1234".to_string());
let value = data.parse_float().unwrap();
assert_eq!(value, 0x1234 as f64);
let data = CharacterData::String("1.234e5".to_string());
let value = data.parse_float().unwrap();
assert_eq!(value, 1.234e5);Sourcepub fn parse_bool(&self) -> Option<bool>
pub fn parse_bool(&self) -> Option<bool>
parse the stored character data value as a boolean
CharacterData doesn’t store a boolean type natively: Autosar describes booleans as strings with the values
“true” or “1” for true, and “false” or “0” for false.
Returns the value if the conversion succeeds, or None otherwise
§Example
let data = CharacterData::String("true".to_string());
let value = data.parse_bool().unwrap();
assert_eq!(value, true);Trait Implementations§
Source§impl Clone for CharacterData
impl Clone for CharacterData
Source§fn clone(&self) -> CharacterData
fn clone(&self) -> CharacterData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CharacterData
impl Debug for CharacterData
Source§impl Display for CharacterData
impl Display for CharacterData
Source§impl From<&str> for CharacterData
impl From<&str> for CharacterData
Source§impl From<EnumItem> for CharacterData
impl From<EnumItem> for CharacterData
Source§impl From<String> for CharacterData
impl From<String> for CharacterData
Source§impl From<bool> for CharacterData
impl From<bool> for CharacterData
Source§impl From<f64> for CharacterData
impl From<f64> for CharacterData
Source§impl From<u64> for CharacterData
impl From<u64> for CharacterData
Source§impl Ord for CharacterData
impl Ord for CharacterData
Source§impl PartialEq for CharacterData
impl PartialEq for CharacterData
Source§impl PartialOrd for CharacterData
impl PartialOrd for CharacterData
impl Eq for CharacterData
impl StructuralPartialEq for CharacterData
Auto Trait Implementations§
impl Freeze for CharacterData
impl RefUnwindSafe for CharacterData
impl Send for CharacterData
impl Sync for CharacterData
impl Unpin for CharacterData
impl UnwindSafe for CharacterData
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.