pub struct Fixed<const P: u32, const S: u32> { /* private fields */ }Expand description
IDL fixed<P, S> decimal with P total digits and S digits
after the decimal point.
Stored as packed BCD bytes (XCDR2 §7.4.4.5). Pure Rust with no
external crate dependency. Deliberate architectural choice: this
type offers roundtrip + string conversion, no decimal
arithmetic (add/mul). End users who need decimal arithmetic combine
it with rust_decimal or similar via a From impl.
Implementations§
Source§impl<const P: u32, const S: u32> Fixed<P, S>
impl<const P: u32, const S: u32> Fixed<P, S>
Sourcepub fn from_bcd_bytes(bytes: Vec<u8>) -> Result<Self, DecodeError>
pub fn from_bcd_bytes(bytes: Vec<u8>) -> Result<Self, DecodeError>
Constructs a Fixed<P, S> from a raw BCD byte sequence.
§Errors
Invalid if the byte length is not (P + 2) / 2.
Sourcepub fn as_bcd_bytes(&self) -> &[u8] ⓘ
pub fn as_bcd_bytes(&self) -> &[u8] ⓘ
Raw BCD bytes.
Sourcepub fn from_str_repr(s: &str) -> Result<Self, DecodeError>
pub fn from_str_repr(s: &str) -> Result<Self, DecodeError>
Creates from a string (e.g. "123.45" or "-1.5").
§Errors
Invalid for non-numeric input or overflow against P/S.
Sourcepub fn to_string_repr(&self) -> String
pub fn to_string_repr(&self) -> String
Decimal string representation (e.g. "123.45").
Trait Implementations§
Source§impl<const P: u32, const S: u32> CdrDecode for Fixed<P, S>
impl<const P: u32, const S: u32> CdrDecode for Fixed<P, S>
Source§fn decode(r: &mut BufferReader<'_>) -> Result<Self, DecodeError>
fn decode(r: &mut BufferReader<'_>) -> Result<Self, DecodeError>
Reads this value from the reader (alignment-aware). Read more
Source§const IS_PRIMITIVE: bool = false
const IS_PRIMITIVE: bool = false
XCDR2 primitive classification, symmetric to
CdrEncode::IS_PRIMITIVE. Controls DHEADER reading when
decoding sequence<T>/T[N] with non-primitive T.Source§impl<const P: u32, const S: u32> CdrEncode for Fixed<P, S>
impl<const P: u32, const S: u32> CdrEncode for Fixed<P, S>
Source§fn encode(&self, w: &mut BufferWriter) -> Result<(), EncodeError>
fn encode(&self, w: &mut BufferWriter) -> Result<(), EncodeError>
Writes this value into the writer (alignment-aware). Read more
Source§const IS_PRIMITIVE: bool = false
const IS_PRIMITIVE: bool = false
XCDR2 primitive classification (OMG XTypes 1.3 §7.4.3.5):
true
only for primitives (bool, octet, int8/16/32/64, uint8/16/32/64,
float, double, char/wchar). false for aggregate/variable
types (string, struct, union, enum, sequence, array, map).
Controls DHEADER prepending for sequence<T>/T[N]:
collections with NON-primitive elements need a DHEADER (uint32 =
byte length of the following content) under XCDR2.impl<const P: u32, const S: u32> Eq for Fixed<P, S>
Source§impl<const P: u32, const S: u32> PartialEq for Fixed<P, S>
impl<const P: u32, const S: u32> PartialEq for Fixed<P, S>
impl<const P: u32, const S: u32> StructuralPartialEq for Fixed<P, S>
Auto Trait Implementations§
impl<const P: u32, const S: u32> Freeze for Fixed<P, S>
impl<const P: u32, const S: u32> RefUnwindSafe for Fixed<P, S>
impl<const P: u32, const S: u32> Send for Fixed<P, S>
impl<const P: u32, const S: u32> Sync for Fixed<P, S>
impl<const P: u32, const S: u32> Unpin for Fixed<P, S>
impl<const P: u32, const S: u32> UnsafeUnpin for Fixed<P, S>
impl<const P: u32, const S: u32> UnwindSafe for Fixed<P, S>
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