CharacterData

Enum CharacterData 

Source
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

Source

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

Source

pub fn string_value(&self) -> Option<String>

Get the contained string

Returns the string if the content is a string, or None otherwise

Source

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

Source

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

Source

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);
Source

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);
Source

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

Source§

fn clone(&self) -> CharacterData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CharacterData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for CharacterData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for CharacterData

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<EnumItem> for CharacterData

Source§

fn from(value: EnumItem) -> Self

Converts to this type from the input type.
Source§

impl From<String> for CharacterData

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for CharacterData

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for CharacterData

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for CharacterData

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl Ord for CharacterData

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for CharacterData

Source§

fn eq(&self, other: &CharacterData) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for CharacterData

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for CharacterData

Source§

impl StructuralPartialEq for CharacterData

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.