Set the bits in the range of `[0, end)` to 0 (if `val` is false), or 1 (if `val` is true). Also extend the length of this buffer to be `end`. This is useful when one wants to clear (or set) the bits and then manipulate the buffer directly (e.g., modifying the buffer by holding a mutable reference from `data_mut()`). # Panics Panics if `end` exceeds the buffer capacity.
(mut self, end: usize, val: bool)
| 227 | /// |
| 228 | /// Panics if `end` exceeds the buffer capacity. |
| 229 | pub fn with_bitset(mut self, end: usize, val: bool) -> Self { |
| 230 | assert!(end <= self.layout.size()); |
| 231 | let v = if val { 255 } else { 0 }; |
| 232 | unsafe { |
| 233 | std::ptr::write_bytes(self.data.as_ptr(), v, end); |
| 234 | self.len = end; |
| 235 | } |
| 236 | self |
| 237 | } |
| 238 | |
| 239 | /// Ensure that `count` bytes from `start` contain zero bits |
| 240 | /// |