rust-ascii icon indicating copy to clipboard operation
rust-ascii copied to clipboard

Add literal macro

Open andrepd opened this issue 2 months ago • 0 comments

This macro enables us to write literal, compile-time, fixed-size ascii strings by writing

const HELLO: &[AsciiChar; 15] = ascii::literal!("Hello in ASCII!");

just as we would write literal, compile-time, fixed-size byte strings by writing

const HELLO: &[u8; 15] = b"Hello in bytes!";

This seems to be currently the only way to (safely) write a string such that its validity is checked at compile-time.

andrepd avatar Nov 17 '25 12:11 andrepd