rust-analyzer / smol_str

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add static string variant

Kestrer opened this issue · comments

Add a new variant which contains a &'static str to allow easily creating a smol str at compile time.

Why? SmolStr::new is probably already constified as a part of optimization - so there wouldn't be a performance benefit. Maybe it should be explicitly marked as a const function though, in order to be able to use it in constants (if that's your goal)

Yeah, I've just released 0.1.17 with const fn new_inline(text: &str) -> SmolStr. If you need to handle long const stirng, I suggest sticking with just &'static str, or maybe wrapping SmolStr into once_cell::Lazy.