1 use crate::rt::compute_raw_varint64_size;
2 
3 /// Helper trait implemented by integer types which could be encoded as varint.
4 pub(crate) trait ProtobufVarint {
5     /// Size of self when encoded as varint.
len_varint(&self) -> u646     fn len_varint(&self) -> u64;
7 }
8 
9 impl ProtobufVarint for u64 {
len_varint(&self) -> u6410     fn len_varint(&self) -> u64 {
11         compute_raw_varint64_size(*self)
12     }
13 }
14 
15 impl ProtobufVarint for u32 {
len_varint(&self) -> u6416     fn len_varint(&self) -> u64 {
17         (*self as u64).len_varint()
18     }
19 }
20 
21 impl ProtobufVarint for i64 {
len_varint(&self) -> u6422     fn len_varint(&self) -> u64 {
23         // same as length of u64
24         (*self as u64).len_varint()
25     }
26 }
27 
28 impl ProtobufVarint for i32 {
len_varint(&self) -> u6429     fn len_varint(&self) -> u64 {
30         // sign-extend and then compute
31         (*self as i64).len_varint()
32     }
33 }
34 
35 impl ProtobufVarint for bool {
len_varint(&self) -> u6436     fn len_varint(&self) -> u64 {
37         1
38     }
39 }
40