| 140 | /// If `len` is greater than the buffer's current length, this has no effect |
| 141 | #[inline] |
| 142 | pub fn truncate(&mut self, len: usize) { |
| 143 | if len > self.len { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | let new_len_bytes = bit_util::ceil(len, 8); |
| 148 | self.buffer.truncate(new_len_bytes); |
| 149 | self.len = len; |
| 150 | |
| 151 | let remainder = self.len % 8; |
| 152 | if remainder != 0 { |
| 153 | let mask = (1_u8 << remainder).wrapping_sub(1); |
| 154 | *self.buffer.as_mut().last_mut().unwrap() &= mask; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /// Reserve space to at least `additional` new bits. |
| 159 | /// Capacity will be `>= self.len() + additional`. |