Skip to main content

gff_label

Macro gff_label 

Source
macro_rules! gff_label {
    ($literal:literal) => { ... };
}
Expand description

Builds a GffLabel from a literal, rejecting an invalid one at compile time.

GffLabel::from_static is a const fn, but calling it in an ordinary expression evaluates it at run time, so a bad literal panics on the line that runs rather than on the line that is wrong. Wrapping the call in a const block forces the evaluation into the compile, which is the whole point at a call site that only ever passes a literal.

let tag = gff_label!("Tag");
assert_eq!(tag.as_str(), "Tag");
let bad = gff_label!("Tag!");