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

Implied bounds for the remaining std::fmt traits #150

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions impl/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ pub struct Transparent<'a> {
pub span: Span,
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub enum Trait {
Debug,
Display,
Octal,
LowerHex,
UpperHex,
Pointer,
Binary,
LowerExp,
UpperExp,
}

pub fn get(input: &[Attribute]) -> Result<Attrs> {
Expand Down Expand Up @@ -200,9 +207,7 @@ impl ToTokens for Display<'_> {

impl ToTokens for Trait {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(match self {
Trait::Debug => quote!(std::fmt::Debug),
Trait::Display => quote!(std::fmt::Display),
});
let trait_name = format_ident!("{}", format!("{:?}", self));
tokens.extend(quote!(std::fmt::#trait_name));
}
}
7 changes: 7 additions & 0 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ impl Display<'_> {
};
let bound = match read[..end_spec].chars().next_back() {
Some('?') => Trait::Debug,
Some('o') => Trait::Octal,
Some('x') => Trait::LowerHex,
Some('X') => Trait::UpperHex,
Some('p') => Trait::Pointer,
Some('b') => Trait::Binary,
Some('e') => Trait::LowerExp,
Some('E') => Trait::UpperExp,
Some(_) => Trait::Display,
None => {
has_bonus_display = true;
Expand Down