Struct actyx_sdk::types::FixNum [−][src]
#[repr(transparent)]pub struct FixNum<T: LeEqU128>(_);
Expand description
This is a helper type that allows JSON numbers to be decoded in a fashion suitable for differential dataflow: it provides equality, hashing, and Abomonation.
If the number does not fit into the range of the fixed-point number, it
will be bounded to the valid number range.
NaN
will be reported as a deserialization error.
Note: this example needs the
dataflow
feature to compile
use actyx_sdk::types::FixNum; use actyx_sdk::types::fixnum_types::*; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Abomonation, Hash)] struct S { x: FixNum<U5>, y: Option<FixNum<U10>>, }
Implementations
Construct a FixNum from a numeric input (like an f64
or u64
), possibly panicking.
Will panic when called with NaN
(because that is not a number and you
shouldn’t be passing that around).
Will panic when the converted number does not fit into FixNum.
let a: FixNum<U12> = FixNum::<U12>::panicking(5); let b: FixNum<U12> = a + 12; assert_eq!(b, FixNum::panicking(17));
Construct a FixNum from a numeric input (like an f64
or u64
), returning an option.
Will panic when called with NaN
(because that is not a number and you
shouldn’t be passing that around).
let a = FixNum::<U32>::checked(5); assert_eq!(a, Some(FixNum::panicking(5)));
Construct a FixNum from a numeric input (like an f64
or u64
), saturating on overflow.
Will panic when called with NaN
(because that is not a number and you
shouldn’t be passing that around).
let a: FixNum<U127> = FixNum::<U127>::saturating(5); assert_eq!(a, FixNum::saturating(1));
Construct a FixNum from a numeric input (like an f64
or u64
).
Will panic when called with NaN
(because that is not a number and you
shouldn’t be passing that around).
let a: FixNum<U127> = FixNum::<U127>::wrapping(1.3); assert_eq!(a, FixNum::panicking(-0.7));
Construct a FixNum from a numeric input (like an f64
or u64
) and returns
also a flag whether an overflow occurred.
Will panic when called with NaN
(because that is not a number and you
shouldn’t be passing that around).
let (a, overflow) = FixNum::<U127>::overflowing(5); assert_eq!(a, FixNum::panicking(-1)); assert!(overflow);
Convert to a primitive number type, panicking on overflow if debug assertions are on.
let f: i8 = FixNum::<U100>::panicking(5).to_num_panicking(); assert_eq!(f, 5);
Convert to a primitive number type, returning an option.
let f: Option<i8> = FixNum::<U100>::panicking(5).to_num_checked(); assert_eq!(f, Some(5)); let f: Option<i8> = FixNum::<U100>::panicking(1000).to_num_checked(); assert_eq!(f, None);
Convert to a primitive number type, saturating on overflow.
let f: i8 = FixNum::<U100>::panicking(130).to_num_saturating(); assert_eq!(f, 127);
Convert to a primitive number type, wrapping on overflow.
let f: i8 = FixNum::<U100>::panicking(130).to_num_wrapping(); assert_eq!(f, -126);
Trait Implementations
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Deserialize this value from the given Serde deserializer. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the <<=
operation. Read more
Performs the >>=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for FixNum<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for FixNum<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Casts the value.
Compare self to key
and return true
if they are equal.
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Performs the conversion.
Performs the conversion.
Casts the value.
Casts the value.
Casts the value.
Casts the value.
impl<T, Rhs> NumAssignOps<Rhs> for T where
T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,
[src]impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,
[src]