pulldown_latex/parser/
storage.rs

1//! Storage for the parser to expand macros call into.
2
3/// This storage is used by the parser to store the expaned content of a macro call. It is only
4/// used when user-defined macros are used. Otherwise, this storage is not used and is _zero-overhead_.
5///
6/// [`Storage`] needs to exist because Rust does not allow self-referencial types. When Rust does
7/// (hopefully) gain support for self-referencial types, this storage will be removed.
8#[derive(Default)]
9pub struct Storage(pub(super) bumpalo::Bump);
10
11impl Storage {
12    /// Create a new storage for the parser.
13    pub fn new() -> Self {
14        Default::default()
15    }
16
17    /// Reset the storage's memory.
18    ///
19    /// It is recommended to call this method after each parsing operation to free up memory. This
20    /// is more efficient than dropping the storage and creating a new one.
21    pub fn reset(&mut self) {
22        self.0.reset();
23    }
24}