Skip to content

Commit 8eab48f

Browse files
committed
refactor(derive): Make it easier to work with 'Name'
1 parent be73195 commit 8eab48f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

clap_derive/src/item.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,8 @@ impl Item {
974974
quote!( #(#doc_comment)* #(#methods)* )
975975
}
976976

977-
pub fn group_id(&self) -> TokenStream {
978-
self.group_id.clone().raw()
977+
pub fn group_id(&self) -> &Name {
978+
&self.group_id
979979
}
980980

981981
pub fn group_methods(&self) -> TokenStream {
@@ -998,8 +998,8 @@ impl Item {
998998
quote!( #(#next_help_heading)* )
999999
}
10001000

1001-
pub fn id(&self) -> TokenStream {
1002-
self.name.clone().raw()
1001+
pub fn id(&self) -> &Name {
1002+
&self.name
10031003
}
10041004

10051005
pub fn cased_name(&self) -> TokenStream {
@@ -1410,16 +1410,6 @@ pub enum Name {
14101410
}
14111411

14121412
impl Name {
1413-
pub fn raw(self) -> TokenStream {
1414-
match self {
1415-
Name::Assigned(tokens) => tokens,
1416-
Name::Derived(ident) => {
1417-
let s = ident.unraw().to_string();
1418-
quote_spanned!(ident.span()=> #s)
1419-
}
1420-
}
1421-
}
1422-
14231413
pub fn translate(self, style: CasingStyle) -> TokenStream {
14241414
use CasingStyle::*;
14251415

@@ -1466,3 +1456,15 @@ impl Name {
14661456
}
14671457
}
14681458
}
1459+
1460+
impl ToTokens for Name {
1461+
fn to_tokens(&self, tokens: &mut TokenStream) {
1462+
match self {
1463+
Name::Assigned(t) => t.to_tokens(tokens),
1464+
Name::Derived(ident) => {
1465+
let s = ident.unraw().to_string();
1466+
quote_spanned!(ident.span()=> #s).to_tokens(tokens)
1467+
}
1468+
}
1469+
}
1470+
}

0 commit comments

Comments
 (0)