External Publication
Visit Post

Sized (or Sizeable) str, e.g. str<const N: usize>

Rust Internals [Unofficial] April 30, 2026
Source

CAD97:

Note that your example could be unsound in the future

Technically not unsound because of the assert! in the constructor. But I take your point that relying on any behavior of :literal is sketchy. The minimal fix is

macro_rules! sizstr {
    ($text:literal) => {
        const {
            const TEXT: &str = $text;
            SizStr::<{ TEXT.len() }>::strict_from_ref(TEXT)
        }
    };
}

Discussion in the ATmosphere

Loading comments...