Skip to content

Commit

Permalink
improve style of macro generation (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl authored Mar 21, 2023
1 parent fc13cff commit 6ecc57a
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions dropshot_endpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,27 +365,17 @@ fn do_endpoint_inner(
.tags
.iter()
.map(|tag| {
quote! {
.tag(#tag)
}
quote! { .tag(#tag) }
})
.collect::<Vec<_>>();

let visible = if metadata.unpublished {
quote! {
.visible(false)
}
} else {
quote! {}
};
let visible = metadata.unpublished.then(|| {
quote! { .visible(false) }
});

let deprecated = if metadata.deprecated {
quote! {
.deprecated(true)
}
} else {
quote! {}
};
let deprecated = metadata.deprecated.then(|| {
quote! { .deprecated(true) }
});

let dropshot = get_crate(metadata._dropshot_crate);

Expand Down Expand Up @@ -492,7 +482,10 @@ fn do_endpoint_inner(
quote! { #argname }
})
.collect::<Vec<_>>();
let impl_checks = if !arg_is_receiver {

// If we have a `self` arg, this check would introduce even more confusing
// error messages, so we only include it if there is no receiver.
let impl_checks = (!arg_is_receiver).then(||
quote! {
const _: fn() = || {
fn future_endpoint_must_be_send<T: ::std::marker::Send>(_t: T) {}
Expand All @@ -501,11 +494,7 @@ fn do_endpoint_inner(
}
};
}
} else {
// If we have a `self` arg, our `future_is_send` check will introduce
// even more confusing error messages, so omit it entirely.
quote! {}
};
);

let ret_check = match &ast.sig.output {
syn::ReturnType::Default => {
Expand Down

0 comments on commit 6ecc57a

Please sign in to comment.