pub struct BigInt {
pub negative: bool,
pub magnitude: Vec<u8>,
}Expand description
An integer of arbitrary size.
This is a well-known extension type (see ext) for
integers that do not fit into 128 bits. It holds the sign and the
magnitude as big-endian bytes. Leading zero bytes are permitted, zero is
never negative.
The fallback is the decimal representation as string. Integers that
fit into 64 or 128 bits are not represented as BigInt: they are
passed through deser as U64, I64, u128 or i128 instead. That is
what the num-bigint support does. When deserializing, all of these as
well as strings are accepted.
use deser::ext::BigInt;
let value: BigInt =
"-340282366920938463463374607431768211456".parse().unwrap();
assert!(value.negative);
assert_eq!(
value.magnitude,
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
);
assert_eq!(value.to_string(), "-340282366920938463463374607431768211456");Values are compared and hashed by their numeric value.
Fields§
§negative: booltrue if the integer is negative.
magnitude: Vec<u8>The magnitude as big-endian bytes.
Implementations§
Source§impl BigInt
impl BigInt
Sourcepub fn significant_magnitude(&self) -> &[u8] ⓘ
pub fn significant_magnitude(&self) -> &[u8] ⓘ
Returns the magnitude without leading zero bytes.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if the value is negative (and not zero).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for BigInt
impl<'de> Deserialize<'de> for BigInt
Source§fn deserialize_atom(
slot: &mut Slot<Self>,
atom: Atom<'_>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_atom( slot: &mut Slot<Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>
Source§fn expecting() -> Cow<'static, str>
fn expecting() -> Cow<'static, str>
Source§fn deserialize_into<'out>(
out: &'out mut Option<T>,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_into<'out>( out: &'out mut Option<T>, state: &mut State, ) -> SinkHandle<'out, 'de>
Source§fn deserialize_borrowed_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'de>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>
Source§fn describe_type(d: &mut dyn Describe)
fn describe_type(d: &mut dyn Describe)
Source§fn initial_value() -> Option<T>
fn initial_value() -> Option<T>
Source§fn deserialize_update<'out>(
value: &'out mut T,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>
impl Eq for BigInt
Source§impl Ord for BigInt
impl Ord for BigInt
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for BigInt
impl PartialOrd for BigInt
Source§impl Serialize for BigInt
impl Serialize for BigInt
Source§fn serialize<'a>(value: &'a Self, _state: &mut State) -> Result<Emit<'a>, Error>
fn serialize<'a>(value: &'a Self, _state: &mut State) -> Result<Emit<'a>, Error>
Source§fn finish(value: &T, state: &mut State) -> Result<(), Error>
fn finish(value: &T, state: &mut State) -> Result<(), Error>
Source§fn container_shape(value: &T) -> ContainerShape
fn container_shape(value: &T) -> ContainerShape
Auto Trait Implementations§
impl Freeze for BigInt
impl RefUnwindSafe for BigInt
impl Send for BigInt
impl Sync for BigInt
impl Unpin for BigInt
impl UnsafeUnpin for BigInt
impl UnwindSafe for BigInt
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> BorrowedExtension for Twhere
T: Extension,
impl<T> BorrowedExtension for Twhere
T: Extension,
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
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.