Skip to main content

ident

Macro ident 

Source
macro_rules! ident {
    ($x:ident) => { ... };
    ($x:expr) => { ... };
    ($head:ident, $($tail:tt)+) => { ... };
    ($head:expr, $($tail:tt)+) => { ... };
    (@accum $acc:ident, $next:ident, $($tail:tt)+) => { ... };
    (@accum $acc:ident, $next:expr, $($tail:tt)+) => { ... };
    (@accum $acc:ident, $last:ident) => { ... };
    (@accum $acc:ident, $last:expr) => { ... };
}
Expand description

Builds an Ident from one or more segments, lexing the result and panicking on invalid identifier syntax.

Accepts a bare identifier, a string/expression that evaluates to a name, or a comma-separated list of segments that are concatenated into a single identifier. Bare identifiers are captured by name via stringify!; expressions are converted with ToString.

§Examples

ⓘ
use moxy::token::ident;

// Bare identifier
let counter = ident!(counter);
assert_eq!(counter, "counter");

// Raw identifier
let kw = ident!(r#struct);
assert_eq!(kw.text(), "struct");
assert!(kw.is_raw());

// From a string or expression
let name = ident!("buffer");
assert_eq!(name, "buffer");

// Concatenate segments into one identifier
let field = ident!(get, "_", value);
assert_eq!(field, "get_value");

// Bare identifier segments are taken by name, not evaluated
let slot = ident!(slot, "_", n);
assert_eq!(slot, "slot_n");

§Panics

Panics if the concatenated text is not a valid identifier.