Skip to main content

Register

Struct Register 

Source
pub struct Register {
    pub unit: Unit,
    pub scaler: i8,
    pub value: i64,
}
Expand description

One register of a TupelEntry: value × 10^scaler in unit, as on the wire (Unsigned8, Integer8, Integer64).

Fields§

§unit: Unit

The unit.

§scaler: i8

The decimal exponent.

§value: i64

The raw value.

Implementations§

Source§

impl Register

Source

pub const fn quantity(self) -> Quantity

The register as an exact Quantity.

Examples found in repository?
examples/decode.rs (line 301)
282fn tree(t: &sml_kit::Tree<'_>, depth: usize) {
283    let name = Obis::from_bytes(t.name).map_or_else(
284        |_| hex(t.name),
285        |o| format!("{o}{}", o.name().map(|n| format!(" ({n})")).unwrap_or_default()),
286    );
287    let value = match t.value {
288        None => String::new(),
289        Some(sml_kit::ProcParValue::Value(SmlValue::Bytes(b))) => format!("= {}", text(b)),
290        Some(sml_kit::ProcParValue::Value(v)) => format!("= {v:?}"),
291        Some(sml_kit::ProcParValue::Entry(e)) => format!(
292            "= {}{}",
293            e.quantity().map_or_else(|| format!("{:?}", e.value), |q| q.to_string()),
294            if e.value_signature.is_some() { " (signed, not verified)" } else { "" }
295        ),
296        Some(sml_kit::ProcParValue::Period(p)) => {
297            format!("= {}", p.quantity().map_or_else(|| format!("{:?}", p.value), |q| q.to_string()))
298        }
299        Some(sml_kit::ProcParValue::Time(t)) => format!("= {t}"),
300        Some(sml_kit::ProcParValue::Tupel(t)) => {
301            format!("= A+ {} A- {}", t.a_plus.quantity(), t.a_minus.quantity())
302        }
303    };
304    println!("{:indent$}{name} {value}", "", indent = 2 * depth + 1);
305    for child in t.children.into_iter().flatten() {
306        match child {
307            Ok(c) => tree(&c, depth + 1),
308            Err(e) => eprintln!("{:indent$}child error: {e}", "", indent = 2 * depth + 3),
309        }
310    }
311}

Trait Implementations§

Source§

impl Clone for Register

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Register

Source§

impl Debug for Register

Source§

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

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

impl Eq for Register

Source§

impl Hash for Register

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Register

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Register

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.