Struct varuint::Varuint [−][src]
pub struct Varuint(pub u128);
Variable length unsigned integer.
Examples
use std::mem; use varuint::{Varuint, Serializable, Deserializable}; use std::io::Read; fn test_varuint(v: u128, size: usize) { let v = Varuint(v); assert_eq!(size, v.size_hint()); let mut arr: [u8; 17] = unsafe { mem::uninitialized() }; { let mut buf = &mut arr as &mut [u8]; assert_eq!(size, v.serialize(&mut buf).unwrap()); } let mut buf: &[u8] = &arr; let mut read: &mut Read = &mut buf; assert_eq!(v, Varuint::deserialize(read).unwrap()); } test_varuint(0, 1); test_varuint(240, 1); test_varuint(241, 2); test_varuint(2031, 2); test_varuint(2032, 3); test_varuint(67567, 3); test_varuint(67568, 4); test_varuint(16777215, 4); test_varuint(16777216, 5); test_varuint(4294967295, 5); test_varuint(4294967296, 6); test_varuint(1099511627775, 6); test_varuint(1099511627776, 7); test_varuint(281474976710655, 7); test_varuint(281474976710656, 8); test_varuint(72057594037927935, 8); test_varuint(72057594037927936, 9); test_varuint(u64::max_value().into(), 9); test_varuint(u64::max_value() as u128 + 1, 17); test_varuint(u128::max_value(), 17);
Methods from Deref<Target = u128>
Trait Implementations
impl Copy for Varuint
[src]
impl Copy for Varuint
impl Clone for Varuint
[src]
impl Clone for Varuint
fn clone(&self) -> Varuint
[src]
fn clone(&self) -> Varuint
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for Varuint
[src]
impl PartialEq for Varuint
fn eq(&self, other: &Varuint) -> bool
[src]
fn eq(&self, other: &Varuint) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Varuint) -> bool
[src]
fn ne(&self, other: &Varuint) -> bool
This method tests for !=
.
impl Eq for Varuint
[src]
impl Eq for Varuint
impl Hash for Varuint
[src]
impl Hash for Varuint
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialOrd for Varuint
[src]
impl PartialOrd for Varuint
fn partial_cmp(&self, other: &Varuint) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Varuint) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Varuint) -> bool
[src]
fn lt(&self, other: &Varuint) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Varuint) -> bool
[src]
fn le(&self, other: &Varuint) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Varuint) -> bool
[src]
fn gt(&self, other: &Varuint) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Varuint) -> bool
[src]
fn ge(&self, other: &Varuint) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Varuint
[src]
impl Ord for Varuint
fn cmp(&self, other: &Varuint) -> Ordering
[src]
fn cmp(&self, other: &Varuint) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl Debug for Varuint
[src]
impl Debug for Varuint
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Display for Varuint
[src]
impl Display for Varuint
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Deref for Varuint
[src]
impl Deref for Varuint
type Target = u128
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
fn deref(&self) -> &Self::Target
Dereferences the value.
impl DerefMut for Varuint
[src]
impl DerefMut for Varuint
impl From<u8> for Varuint
[src]
impl From<u8> for Varuint
impl From<u16> for Varuint
[src]
impl From<u16> for Varuint
impl From<u32> for Varuint
[src]
impl From<u32> for Varuint
impl From<u64> for Varuint
[src]
impl From<u64> for Varuint
impl From<u128> for Varuint
[src]
impl From<u128> for Varuint
impl Default for Varuint
[src]
impl Default for Varuint
impl Deserializable for Varuint
[src]
impl Deserializable for Varuint
fn deserialize(r: &mut Read) -> Result<Varuint>
[src]
fn deserialize(r: &mut Read) -> Result<Varuint>
Deserialize value from a Read
impl Serializable for Varuint
[src]
impl Serializable for Varuint