Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
cynecx committed Oct 15, 2021
1 parent d4ed4a3 commit cd5c860
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn instrument_speculative(
args: InstrumentArgs,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let input = syn::parse_macro_input!(item as MaybeItemFn<MaybeBlock>);
let input = syn::parse_macro_input!(item as MaybeItemFn<TokenStream>);
let instrumented_function_name = input.sig.ident.to_string();
gen_function(
&input.as_ref(),
Expand Down Expand Up @@ -649,19 +649,6 @@ fn gen_block<B: ToTokens>(
)
}

#[derive(Debug, Clone)]
struct MaybeBlock(TokenStream);

impl ToTokens for MaybeBlock {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.0.to_tokens(tokens)
}

fn into_token_stream(self) -> TokenStream {
self.0.into_token_stream()
}
}

#[derive(Debug, Clone)]
struct MaybeItemFn<B: ToTokens> {
attrs: Vec<Attribute>,
Expand All @@ -670,17 +657,17 @@ struct MaybeItemFn<B: ToTokens> {
block: B,
}

impl MaybeItemFn<MaybeBlock> {
fn new(attrs: Vec<Attribute>, vis: Visibility, sig: Signature, block: TokenStream) -> Self {
impl<B: ToTokens> MaybeItemFn<B> {
fn new(attrs: Vec<Attribute>, vis: Visibility, sig: Signature, block: B) -> Self {
Self {
attrs,
vis,
sig,
block: MaybeBlock(block),
block,
}
}

fn as_ref(&self) -> MaybeItemFnRef<'_, MaybeBlock> {
fn as_ref(&self) -> MaybeItemFnRef<'_, B> {
MaybeItemFnRef {
attrs: &self.attrs,
vis: &self.vis,
Expand All @@ -690,7 +677,7 @@ impl MaybeItemFn<MaybeBlock> {
}
}

impl Parse for MaybeItemFn<MaybeBlock> {
impl Parse for MaybeItemFn<TokenStream> {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
let attrs = input.call(syn::Attribute::parse_outer)?;
let vis: Visibility = input.parse()?;
Expand Down

0 comments on commit cd5c860

Please sign in to comment.