How to turn a String into a &'static str?
Box::leak(a_string.into_boxed_str())
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=318fb8465993c554eff090ce10a72ae6
Be careful, though, as this causes memory leaks.In my case, i needed this in the setup of some benchmark test, so not a problem in that case.
#Rust #RustLang #RustTip #MemoryLeak
This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!