-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,821 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::{ | ||
fmt::{ | ||
Debug, | ||
Display, | ||
}, | ||
ops::Deref, | ||
}; | ||
use quote::ToTokens; | ||
use syn::Type; | ||
|
||
pub struct TokenDisplay<T: ToTokens>(T); | ||
|
||
pub type MType = TokenDisplay<Type>; | ||
|
||
impl<T: ToTokens> Debug for TokenDisplay<T> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_fmt(format_args!("{}", self)) | ||
} | ||
} | ||
|
||
impl<T: ToTokens> Display for TokenDisplay<T> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_fmt(format_args!("{}", self.0.to_token_stream())) | ||
} | ||
} | ||
|
||
impl<T: ToTokens> From<T> for TokenDisplay<T> { | ||
fn from(value: T) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl<T: ToTokens> Deref for TokenDisplay<T> { | ||
type Target = T; | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl<T: ToTokens> ToTokens for TokenDisplay<T> { | ||
fn to_token_stream(&self) -> proc_macro2::TokenStream { | ||
self.0.to_token_stream() | ||
} | ||
|
||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { | ||
self.0.to_tokens(tokens) | ||
} | ||
|
||
fn into_token_stream(self) -> proc_macro2::TokenStream | ||
where | ||
Self: Sized, { | ||
self.0.into_token_stream() | ||
} | ||
} | ||
|
||
impl<T: ToTokens + PartialEq> PartialEq<T> for TokenDisplay<T> { | ||
fn eq(&self, other: &T) -> bool { | ||
self.0.eq(other) | ||
} | ||
} |
Oops, something went wrong.