[−][src]Struct varuint::Varint
Variable length signed integer.
Examples
use std::mem; use varuint::{Varint, Serializable, Deserializable}; fn test_varint(v: i128, size: usize) { println!("{}", v); let v = Varint(v); assert_eq!(size, v.size_hint()); let mut arr: [u8; 17] = unsafe { mem::uninitialized() }; assert_eq!(size, v.serialize(&mut (&mut arr as &mut [u8])).unwrap()); assert_eq!(v, Varint::deserialize(&mut (&arr as &[u8])).unwrap()); } test_varint(0, 1); test_varint(1, 1); test_varint(-1, 1); test_varint(-120, 1); test_varint(120, 1); test_varint(-2031/2, 2); test_varint(2031/2, 2); test_varint(-67567/2, 3); test_varint(67567/2, 3); test_varint(-16777215/2, 4); test_varint(16777215/2, 4); test_varint(-4294967295/2, 5); test_varint(4294967295/2, 5); test_varint(-1099511627775/2, 6); test_varint(1099511627775/2, 6); test_varint(-281474976710655/2, 7); test_varint(281474976710655/2, 7); test_varint(-72057594037927935/2, 8); test_varint(72057594037927935/2, 8); test_varint(i64::min_value().into(), 9); test_varint(i64::max_value().into(), 9); test_varint(i128::min_value(), 17); test_varint(i128::max_value(), 17);
Trait Implementations
impl Serializable for Varint<u8>
[src]
impl Serializable for Varint<u16>
[src]
impl Serializable for Varint<u32>
[src]
impl Serializable for Varint<u64>
[src]
impl Serializable for Varint<u128>
[src]
impl Serializable for Varint<i8>
[src]
impl Serializable for Varint<i16>
[src]
impl Serializable for Varint<i32>
[src]
impl Serializable for Varint<i64>
[src]
impl Serializable for Varint<i128>
[src]
impl Deserializable for Varint<u8>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<u16>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<u32>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<u64>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<u128>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<i8>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<i16>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<i32>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<i64>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl Deserializable for Varint<i128>
[src]
fn deserialize(r: &mut dyn Read) -> Result<Self>
[src]
impl<T: PartialOrd + VarintBaseType> PartialOrd<Varint<T>> for Varint<T>
[src]
fn partial_cmp(&self, other: &Varint<T>) -> Option<Ordering>
[src]
fn lt(&self, other: &Varint<T>) -> bool
[src]
fn le(&self, other: &Varint<T>) -> bool
[src]
fn gt(&self, other: &Varint<T>) -> bool
[src]
fn ge(&self, other: &Varint<T>) -> bool
[src]
impl<T: Copy + VarintBaseType> Copy for Varint<T>
[src]
impl<T: PartialEq + VarintBaseType> PartialEq<Varint<T>> for Varint<T>
[src]
impl Default for Varint<u128>
[src]
impl Default for Varint<i8>
[src]
impl Default for Varint<i16>
[src]
impl Default for Varint<i32>
[src]
impl Default for Varint<i64>
[src]
impl Default for Varint<i128>
[src]
impl From<i8> for Varint<i8>
[src]
impl From<i8> for Varint<i16>
[src]
impl From<i8> for Varint<i32>
[src]
impl From<i8> for Varint<i64>
[src]
impl From<i8> for Varint<i128>
[src]
impl From<i16> for Varint<i16>
[src]
impl From<i16> for Varint<i32>
[src]
impl From<i16> for Varint<i64>
[src]
impl From<i16> for Varint<i128>
[src]
impl From<i32> for Varint<i32>
[src]
impl From<i32> for Varint<i64>
[src]
impl From<i32> for Varint<i128>
[src]
impl From<i64> for Varint<i64>
[src]
impl From<i64> for Varint<i128>
[src]
impl From<i128> for Varint<i128>
[src]
impl From<u8> for Varint<u128>
[src]
impl From<u16> for Varint<u128>
[src]
impl From<u32> for Varint<u128>
[src]
impl From<u64> for Varint<u128>
[src]
impl From<u128> for Varint<u128>
[src]
impl<T: Clone + VarintBaseType> Clone for Varint<T>
[src]
fn clone(&self) -> Varint<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Ord + VarintBaseType> Ord for Varint<T>
[src]
fn cmp(&self, other: &Varint<T>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
🔬 This is a nightly-only experimental API. (
clamp
)Returns max if self is greater than max, and min if self is less than min. Otherwise this will return self. Panics if min > max. Read more
impl<T: Eq + VarintBaseType> Eq for Varint<T>
[src]
impl<T: VarintBaseType> DerefMut for Varint<T>
[src]
impl<T: VarintBaseType + Display> Display for Varint<T>
[src]
impl<T: Debug + VarintBaseType> Debug for Varint<T>
[src]
impl<T: Hash + VarintBaseType> Hash for Varint<T>
[src]
fn hash<__HT: Hasher>(&self, state: &mut __HT)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T: VarintBaseType> Deref for Varint<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,