summaryrefslogtreecommitdiff
path: root/rust/macros/concat_idents.rs
blob: 47b6add378d2c38b70d578757d5926de3bfd3897 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: GPL-2.0

use proc_macro2::{
    Ident,
    TokenStream,
    TokenTree, //
};
use syn::{
    parse::{
        Parse,
        ParseStream, //
    },
    Result,
    Token, //
};

pub(crate) struct Input {
    a: Ident,
    _comma: Token![,],
    b: Ident,
}

impl Parse for Input {
    fn parse(input: ParseStream<'_>) -> Result<Self> {
        Ok(Self {
            a: input.parse()?,
            _comma: input.parse()?,
            b: input.parse()?,
        })
    }
}

pub(crate) fn concat_idents(Input { a, b, .. }: Input) -> TokenStream {
    let res = Ident::new(&format!("{a}{b}"), b.span());
    TokenStream::from_iter([TokenTree::Ident(res)])
}