Skip to content

macros: error: use type definitions for reduce complexity #898

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

Open
wants to merge 1 commit into
base: rust
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions rust/macros/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use proc_macro::{token_stream, Group, TokenTree};

pub(crate) type FnTrySimpleParam = Box<dyn Fn(&mut token_stream::IntoIter)-> Option<String>>;

pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
if let Some(TokenTree::Ident(ident)) = it.next() {
Some(ident.to_string())
Expand Down
2 changes: 1 addition & 1 deletion rust/macros/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn param_ops_path(param_type: &str) -> &'static str {

fn try_simple_param_val(
param_type: &str,
) -> Box<dyn Fn(&mut token_stream::IntoIter) -> Option<String>> {
) -> FnTrySimpleParam {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with clippy here. In any case if a type alias is used, I think it should be put in the same module.

Copy link
Member

@ojeda ojeda Sep 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree with @bjorn3, especially if the alias is only used once or a few times.

match param_type {
"bool" => Box::new(try_ident),
"str" => Box::new(|param_it| {
Expand Down