Skip to content

Commit ca9304d

Browse files
committed
impl CompactEncoding for usize
1 parent bca1d81 commit ca9304d

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,23 @@ impl CompactEncoding for u64 {
839839
}
840840
}
841841

842+
impl CompactEncoding for usize {
843+
fn encoded_size(&self) -> Result<usize, EncodingError> {
844+
Ok(encoded_size_usize(*self))
845+
}
846+
847+
fn encode<'a>(&self, buffer: &'a mut [u8]) -> Result<&'a mut [u8], EncodingError> {
848+
encode_usize_var(self, buffer)
849+
}
850+
851+
fn decode(buffer: &[u8]) -> Result<(Self, &[u8]), EncodingError>
852+
where
853+
Self: Sized,
854+
{
855+
decode_usize(buffer)
856+
}
857+
}
858+
842859
impl CompactEncoding for String {
843860
fn encoded_size(&self) -> Result<usize, EncodingError> {
844861
encoded_size_str(self)

0 commit comments

Comments
 (0)