pub macro pp_text_macro {
    (
        $vis:vis macro $name:ident {
            $($text:tt)*
        }
    ) => { ... },
    (
        @internal,
        // The text being munched
        text: [{
            $text:literal
            $($rest_text:tt)*
        }],
        // A pool of unique identifiers.
        free_idents: [{ $($free_idents:tt)* }],
        // The contents of the generated private module.
        private_mod: [{ $($private_mod:tt)* }],
        // The contents of the generated macro..
        macro_inner: [{ $($macro_inner:tt)* }],
        define_macro: [$define_macro:tt],
    ) => { ... },
    (
        @internal,
        text: [{
            $($macro:ident)::+!($($params:tt)*)
            $($rest_text:tt)*
        }],
        free_idents: [{ $($free_idents:tt)* }],
        private_mod: [{ $($private_mod:tt)* }],
        macro_inner: [{ $($macro_inner:tt)* }],
        define_macro: [$define_macro:tt],
    ) => { ... },
    (
        @internal,
        text: [{
            if cfg!( $($cfg:tt)* ) {
                $($true_text:tt)*
            } else {
                $($false_text:tt)*
            }
            $($rest_text:tt)*
        }],
        free_idents: [{ $free_ident:ident $($rest_free_idents:tt)* }],
        private_mod: [{ $($private_mod:tt)* }],
        macro_inner: [{ $($macro_inner:tt)* }],
        define_macro: [{ $vis:vis $name:ident }],
    ) => { ... },
    (
        @internal,
        text: [{
            if cfg!( $($cfg:tt)* ) {
                $($true_text:tt)*
            }
            $($rest_text:tt)*
        }],
        free_idents: [$free_idents:tt],
        private_mod: [$private_mod:tt],
        macro_inner: [$macro_inner:tt],
        define_macro: [$define_macro:tt],
    ) => { ... },
    (
        @internal,
        text: [{}],
        free_idents: [{ $free_ident:ident $($rest_free_idents:tt)* }],
        private_mod: [{ $($private_mod:tt)* }],
        macro_inner: [{ $($macro_inner:tt)* }],
        define_macro: [{ $vis:vis $name:ident }],
    ) => { ... },
}
Expand description

Define a macro that produces a string literal whose contents is revealed or masked based on the current build configuration (cfg!).

Examples

#![feature(decl_macro)]

r3_portkit::pptext::pp_text_macro! {
    macro get_text {
        "endianness = "
        if cfg!(target_endian = "little") { "little" } else { "big" } ", "
        "running on "
        if cfg!(unix) { "a unix-like system" } else { "an unknown kind of system" }
    }
}

// `get_text!()` expands to a string literal that can be used in many
// places where a string literal is expected
const TEXT: &str = concat!(get_text!(), "\n");

assert_eq!(
    TEXT,
    format!(
        "endianness = {}, running on {}\n",
        if cfg!(target_endian = "little") { "little" } else { "big" },
        if cfg!(unix) { "a unix-like system" } else { "an unknown kind of system" },
    ),
);