Integrating an allocator inside a parser that uses recursive data structures
⚓ Rust 📅 2025-10-24 👤 surdeus 👁️ 2Hello, Im writing a parser for a programming language Im working on. The parser struct only contains the token stream, but recently ive been trying to integrate an allocator inside it to optimize some parts of the parsing progress (my Expression is a recursive enum, so references/smart pointers are required). Ive changed the type declarations to make them use Bump from the bumpalo crate for anything that needs allocations, I put the Bump inside the Parser struct so that any time a parsing functions would run I could easily pass the allocator to them, however Ive encountered an error: my parsing function signatures all take a &mut self, but since Expressions use lifetimes for boxes and stuff like that the compiler thinks that every constructed expression actually takes a reference to Parser, which is not really what's happenning. Is there a solution for my issue or should I just use the global rust allocator?
3 posts - 3 participants
🏷️ Rust_feed