lkml.org 
[lkml]   [2022]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 05/28] rust: macros: add `concat_idents!` proc macro
On Monday, November 14th, 2022 at 15:26, Gary Guo <gary@garyguo.net> wrote:


> On Thu, 10 Nov 2022 17:41:17 +0100
> Miguel Ojeda ojeda@kernel.org wrote:
>
> > +pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
> > + let mut it = ts.into_iter();
> > + let a = expect_ident(&mut it);
> > + assert_eq!(expect_punct(&mut it), ',');
> > + let b = expect_ident(&mut it);
> > + assert!(it.next().is_none(), "only two idents can be concatenated");
> > + let res = Ident::new(&(a.to_string() + &b.to_string()), b.span());
>
>
> Probably clearer to write `Ident::new(&format!("{a}{b}"), b.span())`
> here?
>
> Best,
> Gary

I agree that is clearer. I hadn't considered that Ident implements Display when I wrote it.

Cheers,
Björn

\
 
 \ /
  Last update: 2022-11-14 15:40    [W:0.107 / U:0.828 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site