Follow

How to turn a String into a &'static str?

Box::leak(a_string.into_boxed_str())

play.rust-lang.org/?version=st

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.

· · Web · 0 · 2 · 6
Sign in to participate in the conversation
Mastodon for Tech Folks

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!