Skip to content

Commit

Permalink
Inline the macro that generates primitive impls
Browse files Browse the repository at this point in the history
It's not clear this has been supplying a useful level of abstraction
ever since 0f60738
  • Loading branch information
dtolnay committed Aug 22, 2024
1 parent ba41109 commit 074c4b9
Showing 1 changed file with 88 additions and 31 deletions.
119 changes: 88 additions & 31 deletions src/to_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,37 +124,94 @@ impl ToTokens for String {
}
}

macro_rules! primitive {
($($t:ident => $name:ident)*) => {
$(
impl ToTokens for $t {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::$name(*self));
}
}
)*
};
}

primitive! {
i8 => i8_suffixed
i16 => i16_suffixed
i32 => i32_suffixed
i64 => i64_suffixed
i128 => i128_suffixed
isize => isize_suffixed

u8 => u8_suffixed
u16 => u16_suffixed
u32 => u32_suffixed
u64 => u64_suffixed
u128 => u128_suffixed
usize => usize_suffixed

f32 => f32_suffixed
f64 => f64_suffixed

char => character
impl ToTokens for i8 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::i8_suffixed(*self));
}
}

impl ToTokens for i16 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::i16_suffixed(*self));
}
}

impl ToTokens for i32 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::i32_suffixed(*self));
}
}

impl ToTokens for i64 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::i64_suffixed(*self));
}
}

impl ToTokens for i128 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::i128_suffixed(*self));
}
}

impl ToTokens for isize {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::isize_suffixed(*self));
}
}

impl ToTokens for u8 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::u8_suffixed(*self));
}
}

impl ToTokens for u16 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::u16_suffixed(*self));
}
}

impl ToTokens for u32 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::u32_suffixed(*self));
}
}

impl ToTokens for u64 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::u64_suffixed(*self));
}
}

impl ToTokens for u128 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::u128_suffixed(*self));
}
}

impl ToTokens for usize {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::usize_suffixed(*self));
}
}

impl ToTokens for f32 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::f32_suffixed(*self));
}
}

impl ToTokens for f64 {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::f64_suffixed(*self));
}
}

impl ToTokens for char {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Literal::char_suffixed(*self));
}
}

impl ToTokens for bool {
Expand Down

0 comments on commit 074c4b9

Please sign in to comment.