pub struct Varint<T>(pub T);Expand description
LEB128 varint wrapper. Signed integers use the zigzag mapping, matching
protobuf’s sint32 / sint64.
Decoding is lenient about overlong encodings, like
varint::decode_u64. Call the varint::decode_*_canonical functions
directly when canonical form must be enforced.
§Example
use wire_codec::{Decode, Encode, ReadBuf, Varint, WriteBuf};
let mut out = [0u8; 8];
let mut buf = WriteBuf::new(&mut out);
Varint(300_u32).encode(&mut buf).unwrap();
Varint(-1_i64).encode(&mut buf).unwrap();
assert_eq!(buf.written(), &[0xAC, 0x02, 0x01]);
assert_eq!(Varint(300_u32).encoded_size(), 2);
let mut r = ReadBuf::new(&out[..3]);
assert_eq!(Varint::<u32>::decode(&mut r).unwrap(), Varint(300));
assert_eq!(Varint::<i64>::decode(&mut r).unwrap(), Varint(-1));Tuple Fields§
§0: TTrait Implementations§
impl<T: Copy> Copy for Varint<T>
impl<T: Eq> Eq for Varint<T>
Source§impl<T: Ord> Ord for Varint<T>
impl<T: Ord> Ord for Varint<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Varint<T>
impl<T: PartialOrd> PartialOrd for Varint<T>
impl<T: PartialEq> StructuralPartialEq for Varint<T>
Auto Trait Implementations§
impl<T> Freeze for Varint<T>where
T: Freeze,
impl<T> RefUnwindSafe for Varint<T>where
T: RefUnwindSafe,
impl<T> Send for Varint<T>where
T: Send,
impl<T> Sync for Varint<T>where
T: Sync,
impl<T> Unpin for Varint<T>where
T: Unpin,
impl<T> UnsafeUnpin for Varint<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Varint<T>where
T: UnwindSafe,
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