Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ToTokens without reliance on {:?} #297

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions impl/src/attr.rs
Expand Up @@ -230,7 +230,18 @@ impl ToTokens for Display<'_> {

impl ToTokens for Trait {
fn to_tokens(&self, tokens: &mut TokenStream) {
let trait_name = format_ident!("{}", format!("{:?}", self));
tokens.extend(quote!(::core::fmt::#trait_name));
let trait_name = match self {
Trait::Debug => "Debug",
Trait::Display => "Display",
Trait::Octal => "Octal",
Trait::LowerHex => "LowerHex",
Trait::UpperHex => "UpperHex",
Trait::Pointer => "Pointer",
Trait::Binary => "Binary",
Trait::LowerExp => "LowerExp",
Trait::UpperExp => "UpperExp",
};
let ident = Ident::new(trait_name, Span::call_site());
tokens.extend(quote!(::core::fmt::#ident));
}
}