tree_buf/experimental/
scratch.rs

1// TODO: Remove this allow when scratch is used
2#![allow(dead_code)]
3use crate::prelude::*;
4use std::cell::RefCell;
5use std::rc::Rc;
6
7#[derive(Clone)]
8pub struct Scratch {
9    buffers: Rc<RefCell<BufferPool>>,
10}
11
12impl Scratch {
13    pub(crate) fn take_buffer<T: Copy>(&self) -> Buffer<T> {
14        self.buffers.borrow_mut().take()
15    }
16    pub(crate) fn put_buffer<T>(&self, buffer: Buffer<T>) {
17        self.buffers.borrow_mut().put(buffer)
18    }
19}
20
21/// A re-usable object which may increase performance when encoding over and over again
22/// in a loop. Avoids allocations
23pub fn scratch<T: Encodable>() -> Scratch {
24    Scratch { buffers: Default::default() }
25}
26
27pub fn encode_into_with_scratch<T: Encodable>(_value: &T, _scratch: &mut Scratch, _into: &mut Vec<u8>) {
28    todo!()
29}