concat_idents.rs 681 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: GPL-2.0
  2. use proc_macro2::{
  3. Ident,
  4. TokenStream,
  5. TokenTree, //
  6. };
  7. use syn::{
  8. parse::{
  9. Parse,
  10. ParseStream, //
  11. },
  12. Result,
  13. Token, //
  14. };
  15. pub(crate) struct Input {
  16. a: Ident,
  17. _comma: Token![,],
  18. b: Ident,
  19. }
  20. impl Parse for Input {
  21. fn parse(input: ParseStream<'_>) -> Result<Self> {
  22. Ok(Self {
  23. a: input.parse()?,
  24. _comma: input.parse()?,
  25. b: input.parse()?,
  26. })
  27. }
  28. }
  29. pub(crate) fn concat_idents(Input { a, b, .. }: Input) -> TokenStream {
  30. let res = Ident::new(&format!("{a}{b}"), b.span());
  31. TokenStream::from_iter([TokenTree::Ident(res)])
  32. }