Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Can not use in literals? #91

Closed
ANOLASC opened this issue Dec 12, 2022 · 1 comment · Fixed by #92
Closed

Can not use in literals? #91

ANOLASC opened this issue Dec 12, 2022 · 1 comment · Fixed by #92

Comments

@ANOLASC
Copy link

ANOLASC commented Dec 12, 2022

use paste::paste;
macro_rules! vec_insert {
    ($bit: tt) => {
        paste! {
            fn [<vector_insert_ $bit _bit>](insert_size: usize) {
                let mut [<vec_ $bit>] = Vec::new();
                for _ in 0..insert_size {
                    [<vec_ $bit>].insert(0, [<1_u $bit>]);
                }
            }
        }
    };
}

vec_insert!(32);

expected to expand into

fn vector_insert_32_bit(insert_size: usize) {
    let mut vec_32 = Vec::new();
    for _ in 0..insert_size {
        vec_32.insert(0, 1_u32);
    }
}

but it show error:
`"1_u32"` is not a valid identifier

Can paste used in literal such as 1_u32?

@dtolnay
Copy link
Owner

dtolnay commented Dec 12, 2022

Should work as of paste 1.0.10.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants