When to Use Box::leak in Rust?
Hi everyone,
I've been exploring the usage of Box::leak in Rust and wanted to get some insights. In my current project, I'm implementing an application where a buffer is dynamically created at the beginning of the program. This buffer is shared among multiple threads and needs to persist until the end of the program's execution.
My line of thinking was to create the buffer like this:
buffer: &'static mut [...]
by using Box::leak.
My intention was to avoid using Arc (but I need a Mutex) in this scenario. However, I'm not entirely sure if this approach is correct or if there are other benefits and downsides to consider.
Can anyone provide some guidance or share their experiences with using Box::leak
in similar situations and when you used it? Your insights would be greatly appreciated!
Thank you!