pub struct VarIntEncoder<'a, T: VarInt = u64> { /* private fields */ }
Expand description
Batch encoder for VarInt values with state management
Implementations§
Source§impl<'a, T: VarInt> VarIntEncoder<'a, T>
impl<'a, T: VarInt> VarIntEncoder<'a, T>
Sourcepub fn new(buf: &'a mut [u8]) -> Self
pub fn new(buf: &'a mut [u8]) -> Self
Creates a new encoder with the provided buffer
Examples found in repository?
examples/protocol_serialization.rs (line 50)
48 fn serialize(&self, buffer: &mut [u8]) -> Result<usize, Error> {
49 // Use VarIntEncoder for serialization
50 let mut encoder = VarIntEncoder::<u32>::new(buffer);
51
52 // Serialize message ID (varint) - using u32 implementation instead of u64
53 encoder.write(self.message_id as u32)?;
54
55 // Serialize temperature (zigzag varint)
56 encoder.write_zigzag(self.temperature)?;
57
58 // Serialize humidity (zigzag varint)
59 encoder.write_zigzag(self.humidity)?;
60
61 // Serialize payload length
62 encoder.write(self.payload.len() as u32)?;
63
64 // Write payload bytes
65 let current_offset = encoder.position();
66 if current_offset + self.payload.len() > buffer.len() {
67 return Err(Error::BufferTooSmall {
68 needed: current_offset + self.payload.len(),
69 actual: buffer.len(),
70 });
71 }
72
73 buffer[current_offset..current_offset + self.payload.len()]
74 .copy_from_slice(&self.payload);
75
76 Ok(current_offset + self.payload.len())
77 }
More examples
examples/iter_example.rs (line 48)
15fn main() {
16 println!("=== Iterator-based API Example ===\n");
17
18 // 1. Encoding a single value using VarIntBytesIter iterator
19 println!("1. Encoding a single value using VarIntBytesIter iterator:");
20 let value = 16384u64;
21
22 println!(" Encoding value: {}", value);
23 println!(" Expected bytes: {}", tiny_varint::varint_size(value));
24
25 print!(" Encoded bytes: [ ");
26 for byte in bytes_of(value) {
27 print!("{:#04x} ", byte);
28 }
29 println!("]");
30
31 // Manually verify the result
32 let mut manual_buf = [0u8; 10];
33 let manual_size = tiny_varint::encode(value, &mut manual_buf).unwrap();
34
35 print!(" Verification bytes: [ ");
36 for i in 0..manual_size {
37 print!("{:#04x} ", manual_buf[i]);
38 }
39 println!("]\n");
40
41 // 2. Decoding using VarIntValuesIter iterator
42 println!("2. Decoding using VarIntValuesIter iterator:");
43
44 // Create a buffer containing multiple varints
45 let values = [0u64, 1, 127, 128, 16383, 16384, 2097151];
46 let mut buffer = [0u8; 100];
47
48 let mut encoder = VarIntEncoder::new(&mut buffer);
49 let bytes_written = encoder.write_batch(&values).unwrap();
50
51 print!(" Encoded bytes: [ ");
52 for i in 0..bytes_written {
53 print!("{:#04x} ", buffer[i]);
54 }
55 println!("]");
56
57 println!(" Decoded values:");
58 for result in values_from::<u64>(&buffer[..bytes_written]) {
59 match result {
60 Ok(value) => println!(" - {}", value),
61 Err(e) => println!(" - Error: {:?}", e),
62 }
63 }
64
65 // 3. Processing zigzag-encoded values without intermediate buffers
66 println!("\n3. Processing zigzag-encoded signed values:");
67
68 let signed_values = [-100i32, -50, -10, -1, 0, 1, 10, 50, 100];
69 println!(" Original values: {:?}", signed_values);
70
71 // Create a zigzag-encoded byte iterator for each value
72 for &value in &signed_values {
73 // First apply zigzag encoding
74 let mut buf = [0u8; 10];
75 let size = encode_zigzag(value, &mut buf).unwrap();
76
77 print!(" ZigZag encoding for {}: [ ", value);
78 for i in 0..size {
79 print!("{:#04x} ", buf[i]);
80 }
81 println!("]");
82 }
83
84 // 4. Combining iterators with encoders/decoders
85 println!("\n4. Combining iterators with encoders/decoders in stream processing:");
86
87 // Simulate a simple data processing pipeline
88 println!(" Data processing pipeline:");
89 println!(" 1. Generate raw data");
90 println!(" 2. Encode using iterator-based methods");
91 println!(" 3. Process encoded bytes");
92 println!(" 4. Decode using iterator-based methods");
93
94 // Raw data
95 let source_data = [42u64, 314, 2718, 31415];
96 println!("\n Raw data: {:?}", source_data);
97
98 // Encode and collect
99 let mut encoded_bytes = Vec::new();
100
101 for &value in &source_data {
102 let encoder = bytes_of(value);
103 println!(" Encoding {} -> {} bytes", value, encoder.size());
104
105 // Add bytes to our buffer
106 for byte in encoder {
107 encoded_bytes.push(byte);
108 }
109 }
110
111 print!(" All encoded bytes: [ ");
112 for byte in &encoded_bytes {
113 print!("{:#04x} ", byte);
114 }
115 println!("]");
116
117 // Decode bytes
118 println!("\n Decoding results:");
119 let decoder = values_from::<u64>(&encoded_bytes);
120
121 let mut i = 0;
122 for result in decoder {
123 match result {
124 Ok(value) => {
125 println!(" Original: {}, Decoded: {}", source_data[i], value);
126 i += 1;
127 }
128 Err(e) => println!(" Error: {:?}", e),
129 }
130 }
131
132 println!("\n=== Example Complete ===");
133}
examples/basic_usage.rs (line 63)
16fn main() {
17 println!("=== tiny-varint Basic Example (no-alloc version) ===\n");
18
19 // 1. Single unsigned integer encoding/decoding
20 println!("1. Encoding and decoding single unsigned integers:");
21 let values = [0u64, 127, 128, 16383, 16384, 2097151];
22
23 for &value in &values {
24 let mut buf = [0u8; 10];
25 let bytes_written = encode(value, &mut buf).unwrap();
26
27 print!(" Value {} encoded as {} bytes: [ ", value, bytes_written);
28 for i in 0..bytes_written {
29 print!("{:#04x} ", buf[i]);
30 }
31 println!("]");
32
33 let (decoded, bytes_read) = decode::<u64>(&buf).unwrap();
34 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
35 println!();
36 }
37
38 // 2. Signed integer zigzag encoding/decoding
39 println!("\n2. ZigZag encoding and decoding of signed integers:");
40 let signed_values = [0i32, 1, -1, 2, -2, 127, -127, 128, -128];
41
42 for &value in &signed_values {
43 let mut buf = [0u8; 10];
44 let bytes_written = encode_zigzag(value, &mut buf).unwrap();
45
46 print!(" Value {} encoded as {} bytes: [ ", value, bytes_written);
47 for i in 0..bytes_written {
48 print!("{:#04x} ", buf[i]);
49 }
50 println!("]");
51
52 let (decoded, bytes_read) = decode_zigzag::<i32>(&buf).unwrap();
53 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
54 println!();
55 }
56
57 // 3. Batch processing using VarIntEncoder/VarIntDecoder
58 println!("\n3. Batch processing using VarIntEncoder/VarIntDecoder:");
59 let batch_values = [1u64, 127, 128, 16383, 16384, 2097151];
60 let mut buffer = [0u8; 100];
61
62 // Using encoder
63 let mut encoder = VarIntEncoder::new(&mut buffer);
64 let bytes_written = encoder.write_batch(&batch_values).unwrap();
65
66 println!(" Encoded {} values using {} bytes", batch_values.len(), bytes_written);
67
68 print!(" Encoded bytes: [ ");
69 for i in 0..bytes_written {
70 print!("{:#04x} ", buffer[i]);
71 }
72 println!("]");
73
74 // Using decoder
75 let mut decoder = VarIntDecoder::new(&buffer[..bytes_written]);
76 let mut decoded = [0u64; 6];
77 let count = decoder.read_batch(&mut decoded).unwrap();
78
79 print!(" Decoded values: [ ");
80 for i in 0..count {
81 print!("{} ", decoded[i]);
82 }
83 println!("]");
84 println!(" Read {} bytes in total", decoder.position());
85
86 // 4. Using different integer types
87 println!("\n4. Using different integer types:");
88
89 // Using u64 type
90 let value = 16384u64;
91 let mut buf = [0u8; 10];
92 let size = encode(value, &mut buf).unwrap();
93
94 print!(" u64 value {} encoded as {} bytes: [ ", value, size);
95 for i in 0..size {
96 print!("{:#04x} ", buf[i]);
97 }
98 println!("]");
99
100 let (decoded, bytes_read) = decode::<u64>(&buf).unwrap();
101 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
102
103 // Using u32 type
104 let u32_value = 42u32;
105 let mut buf = [0u8; 10];
106 let size = encode(u32_value, &mut buf).unwrap();
107
108 print!(" u32 value {} encoded as {} bytes: [ ", u32_value, size);
109 for i in 0..size {
110 print!("{:#04x} ", buf[i]);
111 }
112 println!("]");
113
114 let (decoded, bytes_read) = decode::<u32>(&buf).unwrap();
115 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
116
117 // Using i16 type
118 let i16_value = -256i16;
119 let size = encode(i16_value, &mut buf).unwrap();
120
121 print!(" i16 value {} encoded as {} bytes: [ ", i16_value, size);
122 for i in 0..size {
123 print!("{:#04x} ", buf[i]);
124 }
125 println!("]");
126
127 let (decoded, bytes_read) = decode::<i16>(&buf).unwrap();
128 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
129
130 // 5. Error handling
131 println!("\n5. Error handling:");
132 let large_value: u64 = 0xFFFFFFFFFFFFFFFF; // Requires 10 bytes
133 let mut small_buf = [0u8; 5];
134
135 match encode(large_value, &mut small_buf) {
136 Ok(_) => println!(" Encoding successful (should not reach here)"),
137 Err(Error::BufferTooSmall { needed, actual }) => {
138 println!(" Buffer too small: needed {} bytes, but only had {} bytes", needed, actual);
139 }
140 Err(e) => println!(" Error occurred: {:?}", e),
141 }
142
143 // Create an incomplete varint - flag bit is 1 but no following bytes
144 let incomplete_buf = [0x80];
145
146 match decode::<u64>(&incomplete_buf) {
147 Ok(_) => println!(" Decoding successful (should not reach here)"),
148 Err(Error::InputTooShort) => {
149 println!(" Input too short: high bit is 1 indicating more bytes follow, but data ended");
150 }
151 Err(e) => println!(" Error occurred: {:?}", e),
152 }
153
154 println!("\n=== Example Complete ===");
155}
Sourcepub fn position(&self) -> usize
pub fn position(&self) -> usize
Gets the current position in the buffer
Examples found in repository?
examples/protocol_serialization.rs (line 65)
48 fn serialize(&self, buffer: &mut [u8]) -> Result<usize, Error> {
49 // Use VarIntEncoder for serialization
50 let mut encoder = VarIntEncoder::<u32>::new(buffer);
51
52 // Serialize message ID (varint) - using u32 implementation instead of u64
53 encoder.write(self.message_id as u32)?;
54
55 // Serialize temperature (zigzag varint)
56 encoder.write_zigzag(self.temperature)?;
57
58 // Serialize humidity (zigzag varint)
59 encoder.write_zigzag(self.humidity)?;
60
61 // Serialize payload length
62 encoder.write(self.payload.len() as u32)?;
63
64 // Write payload bytes
65 let current_offset = encoder.position();
66 if current_offset + self.payload.len() > buffer.len() {
67 return Err(Error::BufferTooSmall {
68 needed: current_offset + self.payload.len(),
69 actual: buffer.len(),
70 });
71 }
72
73 buffer[current_offset..current_offset + self.payload.len()]
74 .copy_from_slice(&self.payload);
75
76 Ok(current_offset + self.payload.len())
77 }
Sourcepub fn write(&mut self, value: T) -> Result<usize, Error>
pub fn write(&mut self, value: T) -> Result<usize, Error>
Writes a VarInt value to the buffer
Returns the number of bytes written
Examples found in repository?
examples/protocol_serialization.rs (line 53)
48 fn serialize(&self, buffer: &mut [u8]) -> Result<usize, Error> {
49 // Use VarIntEncoder for serialization
50 let mut encoder = VarIntEncoder::<u32>::new(buffer);
51
52 // Serialize message ID (varint) - using u32 implementation instead of u64
53 encoder.write(self.message_id as u32)?;
54
55 // Serialize temperature (zigzag varint)
56 encoder.write_zigzag(self.temperature)?;
57
58 // Serialize humidity (zigzag varint)
59 encoder.write_zigzag(self.humidity)?;
60
61 // Serialize payload length
62 encoder.write(self.payload.len() as u32)?;
63
64 // Write payload bytes
65 let current_offset = encoder.position();
66 if current_offset + self.payload.len() > buffer.len() {
67 return Err(Error::BufferTooSmall {
68 needed: current_offset + self.payload.len(),
69 actual: buffer.len(),
70 });
71 }
72
73 buffer[current_offset..current_offset + self.payload.len()]
74 .copy_from_slice(&self.payload);
75
76 Ok(current_offset + self.payload.len())
77 }
Sourcepub fn write_batch(&mut self, values: &[T]) -> Result<usize, Error>
pub fn write_batch(&mut self, values: &[T]) -> Result<usize, Error>
Writes a batch of VarInt values
Returns the total number of bytes written
Examples found in repository?
examples/iter_example.rs (line 49)
15fn main() {
16 println!("=== Iterator-based API Example ===\n");
17
18 // 1. Encoding a single value using VarIntBytesIter iterator
19 println!("1. Encoding a single value using VarIntBytesIter iterator:");
20 let value = 16384u64;
21
22 println!(" Encoding value: {}", value);
23 println!(" Expected bytes: {}", tiny_varint::varint_size(value));
24
25 print!(" Encoded bytes: [ ");
26 for byte in bytes_of(value) {
27 print!("{:#04x} ", byte);
28 }
29 println!("]");
30
31 // Manually verify the result
32 let mut manual_buf = [0u8; 10];
33 let manual_size = tiny_varint::encode(value, &mut manual_buf).unwrap();
34
35 print!(" Verification bytes: [ ");
36 for i in 0..manual_size {
37 print!("{:#04x} ", manual_buf[i]);
38 }
39 println!("]\n");
40
41 // 2. Decoding using VarIntValuesIter iterator
42 println!("2. Decoding using VarIntValuesIter iterator:");
43
44 // Create a buffer containing multiple varints
45 let values = [0u64, 1, 127, 128, 16383, 16384, 2097151];
46 let mut buffer = [0u8; 100];
47
48 let mut encoder = VarIntEncoder::new(&mut buffer);
49 let bytes_written = encoder.write_batch(&values).unwrap();
50
51 print!(" Encoded bytes: [ ");
52 for i in 0..bytes_written {
53 print!("{:#04x} ", buffer[i]);
54 }
55 println!("]");
56
57 println!(" Decoded values:");
58 for result in values_from::<u64>(&buffer[..bytes_written]) {
59 match result {
60 Ok(value) => println!(" - {}", value),
61 Err(e) => println!(" - Error: {:?}", e),
62 }
63 }
64
65 // 3. Processing zigzag-encoded values without intermediate buffers
66 println!("\n3. Processing zigzag-encoded signed values:");
67
68 let signed_values = [-100i32, -50, -10, -1, 0, 1, 10, 50, 100];
69 println!(" Original values: {:?}", signed_values);
70
71 // Create a zigzag-encoded byte iterator for each value
72 for &value in &signed_values {
73 // First apply zigzag encoding
74 let mut buf = [0u8; 10];
75 let size = encode_zigzag(value, &mut buf).unwrap();
76
77 print!(" ZigZag encoding for {}: [ ", value);
78 for i in 0..size {
79 print!("{:#04x} ", buf[i]);
80 }
81 println!("]");
82 }
83
84 // 4. Combining iterators with encoders/decoders
85 println!("\n4. Combining iterators with encoders/decoders in stream processing:");
86
87 // Simulate a simple data processing pipeline
88 println!(" Data processing pipeline:");
89 println!(" 1. Generate raw data");
90 println!(" 2. Encode using iterator-based methods");
91 println!(" 3. Process encoded bytes");
92 println!(" 4. Decode using iterator-based methods");
93
94 // Raw data
95 let source_data = [42u64, 314, 2718, 31415];
96 println!("\n Raw data: {:?}", source_data);
97
98 // Encode and collect
99 let mut encoded_bytes = Vec::new();
100
101 for &value in &source_data {
102 let encoder = bytes_of(value);
103 println!(" Encoding {} -> {} bytes", value, encoder.size());
104
105 // Add bytes to our buffer
106 for byte in encoder {
107 encoded_bytes.push(byte);
108 }
109 }
110
111 print!(" All encoded bytes: [ ");
112 for byte in &encoded_bytes {
113 print!("{:#04x} ", byte);
114 }
115 println!("]");
116
117 // Decode bytes
118 println!("\n Decoding results:");
119 let decoder = values_from::<u64>(&encoded_bytes);
120
121 let mut i = 0;
122 for result in decoder {
123 match result {
124 Ok(value) => {
125 println!(" Original: {}, Decoded: {}", source_data[i], value);
126 i += 1;
127 }
128 Err(e) => println!(" Error: {:?}", e),
129 }
130 }
131
132 println!("\n=== Example Complete ===");
133}
More examples
examples/basic_usage.rs (line 64)
16fn main() {
17 println!("=== tiny-varint Basic Example (no-alloc version) ===\n");
18
19 // 1. Single unsigned integer encoding/decoding
20 println!("1. Encoding and decoding single unsigned integers:");
21 let values = [0u64, 127, 128, 16383, 16384, 2097151];
22
23 for &value in &values {
24 let mut buf = [0u8; 10];
25 let bytes_written = encode(value, &mut buf).unwrap();
26
27 print!(" Value {} encoded as {} bytes: [ ", value, bytes_written);
28 for i in 0..bytes_written {
29 print!("{:#04x} ", buf[i]);
30 }
31 println!("]");
32
33 let (decoded, bytes_read) = decode::<u64>(&buf).unwrap();
34 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
35 println!();
36 }
37
38 // 2. Signed integer zigzag encoding/decoding
39 println!("\n2. ZigZag encoding and decoding of signed integers:");
40 let signed_values = [0i32, 1, -1, 2, -2, 127, -127, 128, -128];
41
42 for &value in &signed_values {
43 let mut buf = [0u8; 10];
44 let bytes_written = encode_zigzag(value, &mut buf).unwrap();
45
46 print!(" Value {} encoded as {} bytes: [ ", value, bytes_written);
47 for i in 0..bytes_written {
48 print!("{:#04x} ", buf[i]);
49 }
50 println!("]");
51
52 let (decoded, bytes_read) = decode_zigzag::<i32>(&buf).unwrap();
53 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
54 println!();
55 }
56
57 // 3. Batch processing using VarIntEncoder/VarIntDecoder
58 println!("\n3. Batch processing using VarIntEncoder/VarIntDecoder:");
59 let batch_values = [1u64, 127, 128, 16383, 16384, 2097151];
60 let mut buffer = [0u8; 100];
61
62 // Using encoder
63 let mut encoder = VarIntEncoder::new(&mut buffer);
64 let bytes_written = encoder.write_batch(&batch_values).unwrap();
65
66 println!(" Encoded {} values using {} bytes", batch_values.len(), bytes_written);
67
68 print!(" Encoded bytes: [ ");
69 for i in 0..bytes_written {
70 print!("{:#04x} ", buffer[i]);
71 }
72 println!("]");
73
74 // Using decoder
75 let mut decoder = VarIntDecoder::new(&buffer[..bytes_written]);
76 let mut decoded = [0u64; 6];
77 let count = decoder.read_batch(&mut decoded).unwrap();
78
79 print!(" Decoded values: [ ");
80 for i in 0..count {
81 print!("{} ", decoded[i]);
82 }
83 println!("]");
84 println!(" Read {} bytes in total", decoder.position());
85
86 // 4. Using different integer types
87 println!("\n4. Using different integer types:");
88
89 // Using u64 type
90 let value = 16384u64;
91 let mut buf = [0u8; 10];
92 let size = encode(value, &mut buf).unwrap();
93
94 print!(" u64 value {} encoded as {} bytes: [ ", value, size);
95 for i in 0..size {
96 print!("{:#04x} ", buf[i]);
97 }
98 println!("]");
99
100 let (decoded, bytes_read) = decode::<u64>(&buf).unwrap();
101 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
102
103 // Using u32 type
104 let u32_value = 42u32;
105 let mut buf = [0u8; 10];
106 let size = encode(u32_value, &mut buf).unwrap();
107
108 print!(" u32 value {} encoded as {} bytes: [ ", u32_value, size);
109 for i in 0..size {
110 print!("{:#04x} ", buf[i]);
111 }
112 println!("]");
113
114 let (decoded, bytes_read) = decode::<u32>(&buf).unwrap();
115 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
116
117 // Using i16 type
118 let i16_value = -256i16;
119 let size = encode(i16_value, &mut buf).unwrap();
120
121 print!(" i16 value {} encoded as {} bytes: [ ", i16_value, size);
122 for i in 0..size {
123 print!("{:#04x} ", buf[i]);
124 }
125 println!("]");
126
127 let (decoded, bytes_read) = decode::<i16>(&buf).unwrap();
128 println!(" Decoded: {} (read {} bytes)", decoded, bytes_read);
129
130 // 5. Error handling
131 println!("\n5. Error handling:");
132 let large_value: u64 = 0xFFFFFFFFFFFFFFFF; // Requires 10 bytes
133 let mut small_buf = [0u8; 5];
134
135 match encode(large_value, &mut small_buf) {
136 Ok(_) => println!(" Encoding successful (should not reach here)"),
137 Err(Error::BufferTooSmall { needed, actual }) => {
138 println!(" Buffer too small: needed {} bytes, but only had {} bytes", needed, actual);
139 }
140 Err(e) => println!(" Error occurred: {:?}", e),
141 }
142
143 // Create an incomplete varint - flag bit is 1 but no following bytes
144 let incomplete_buf = [0x80];
145
146 match decode::<u64>(&incomplete_buf) {
147 Ok(_) => println!(" Decoding successful (should not reach here)"),
148 Err(Error::InputTooShort) => {
149 println!(" Input too short: high bit is 1 indicating more bytes follow, but data ended");
150 }
151 Err(e) => println!(" Error occurred: {:?}", e),
152 }
153
154 println!("\n=== Example Complete ===");
155}
Sourcepub fn write_u64(&mut self, value: u64) -> Result<usize, Error>
pub fn write_u64(&mut self, value: u64) -> Result<usize, Error>
Writes a u64 value to the buffer (convenience method)
Returns the number of bytes written
Sourcepub fn write_u128(&mut self, value: u128) -> Result<usize, Error>
pub fn write_u128(&mut self, value: u128) -> Result<usize, Error>
Writes a u128 value to the buffer (convenience method)
Returns the number of bytes written
Sourcepub fn write_zigzag<S>(&mut self, value: S) -> Result<usize, Error>
pub fn write_zigzag<S>(&mut self, value: S) -> Result<usize, Error>
Writes a signed value using zigzag encoding
Returns the number of bytes written
Examples found in repository?
examples/protocol_serialization.rs (line 56)
48 fn serialize(&self, buffer: &mut [u8]) -> Result<usize, Error> {
49 // Use VarIntEncoder for serialization
50 let mut encoder = VarIntEncoder::<u32>::new(buffer);
51
52 // Serialize message ID (varint) - using u32 implementation instead of u64
53 encoder.write(self.message_id as u32)?;
54
55 // Serialize temperature (zigzag varint)
56 encoder.write_zigzag(self.temperature)?;
57
58 // Serialize humidity (zigzag varint)
59 encoder.write_zigzag(self.humidity)?;
60
61 // Serialize payload length
62 encoder.write(self.payload.len() as u32)?;
63
64 // Write payload bytes
65 let current_offset = encoder.position();
66 if current_offset + self.payload.len() > buffer.len() {
67 return Err(Error::BufferTooSmall {
68 needed: current_offset + self.payload.len(),
69 actual: buffer.len(),
70 });
71 }
72
73 buffer[current_offset..current_offset + self.payload.len()]
74 .copy_from_slice(&self.payload);
75
76 Ok(current_offset + self.payload.len())
77 }
Auto Trait Implementations§
impl<'a, T> Freeze for VarIntEncoder<'a, T>
impl<'a, T> RefUnwindSafe for VarIntEncoder<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for VarIntEncoder<'a, T>where
T: Send,
impl<'a, T> Sync for VarIntEncoder<'a, T>where
T: Sync,
impl<'a, T> Unpin for VarIntEncoder<'a, T>where
T: Unpin,
impl<'a, T = u64> !UnwindSafe for VarIntEncoder<'a, T>
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