Scratch space to bridge gap between pack_ints and pack_bytes. In theory, we could avoid this intermediate step, but it would result in a lot of generated code.
(f: impl FnOnce(&mut Vec<u8>) -> T)
| 235 | // Scratch space to bridge gap between pack_ints and pack_bytes. |
| 236 | // In theory, we could avoid this intermediate step, but it would result in a lot of generated code. |
| 237 | fn with_scratch<T>(f: impl FnOnce(&mut Vec<u8>) -> T) -> T { |
| 238 | thread_local! { |
| 239 | static SCRATCH: std::cell::RefCell<Vec<u8>> = Default::default(); |
| 240 | } |
| 241 | SCRATCH.with(|s| { |
| 242 | let s = &mut s.borrow_mut(); |
| 243 | s.clear(); |
| 244 | f(s) |
| 245 | }) |
| 246 | } |
| 247 | macro_rules! impl_u8 { |
| 248 | () => { |
| 249 | fn pack8(v: &mut [Self], out: &mut Vec<u8>) { |