Skip to content
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

modified to repect serde rename directive for struct fields #47

Merged
merged 8 commits into from
Jan 2, 2024

Conversation

aaronh-mood
Copy link
Contributor

Modified tests and some of the big for loops abstracting some of the logic to other functions. Mostly personal preference but I do believe that there are some Rust performance gains when using iterators and chaining compared to for loops. (I'm not 100% certain though).

For the Debug flag, added a state::InitCell which is populated once the entry point is called, so you don't have to pass around the "debug" flag to all methods and callers.

In the main lib.rs file - changed the path parameter from Pathbuf to P: AsRef<Path> so now you can pass around references, rather than cloning the path object.

Tests all complete and output looks similar to existing tests in the repo. No disrespect intended with re-writing some of the methods, just something fun to play around with. If you don't like it or want it, let me know and I can modify the request to only include the part that applies directly to struct field names.

Thanks!

src/utils.rs Outdated
Comment on lines 45 to 49
// this detects the '(...)' part in #[serde(rename_all = "UPPERCASE", tag = "type")]
// we can use this to get the value of a particular argument
// or to see if it exists at all

// make sure the delimiter is what we're expecting
Copy link
Owner

Choose a reason for hiding this comment

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

this comment seems to have been duplicated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed in the latest commits.

@@ -10,177 +23,154 @@ pub fn has_attribute(needle: &str, attributes: &[syn::Attribute]) -> bool {
})
}

fn check_expression_is_path(expr: Expr) -> Option<ExprPath> {
Copy link
Owner

@Wulf Wulf Dec 10, 2023

Choose a reason for hiding this comment

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

could I request you add a comment explaining this method? (why would someone want to use this?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem. I took a shot in the latest commits. Please let me know what you think.

src/utils.rs Outdated
}

/// Check has an attribute arg.
pub fn has_attribute_arg(needle: &str, arg: &str, attributes: &[syn::Attribute]) -> bool {
get_attribute_arg(needle, arg, attributes).is_some()
}

fn check_token_tree(tt: proc_macro2::TokenTree) -> Option<String> {
Copy link
Owner

Choose a reason for hiding this comment

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

could we also add a comment on how and when to use this method?

Similar to:

// this detects the '(...)' part in #[serde(rename_all = "UPPERCASE", tag = "type")]
// we can use this to get the value of a particular argument
// or to see if it exists at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem. I took a shot in the latest commits. Please let me know what you think.

"String" => "string".to_owned().into(),
"NaiveDateTime" => "Date".to_owned().into(),
"DateTime" => "Date".to_owned().into(),
"Uuid" => "string".to_owned().into(),
Copy link
Owner

Choose a reason for hiding this comment

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

🙌

Copy link
Owner

Choose a reason for hiding this comment

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

(thanks for adding Uuid here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. I actually needed it in my use case, so it worked out.

Comment on lines 52 to 53
"Uuid" => "string".to_owned().into(),
x if x.contains("Cow") => "string".to_owned().into(),
Copy link
Owner

Choose a reason for hiding this comment

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

This worries me a bit! What if someone uses Cow in their struct/enum name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree and was definitely short-sighted, I abstracted the check to a method in the latest commits. It should grab the T from Cow<'_, T>, and send the T back through the original method. Please let me know what you think.

}

/** Time in UTC seconds */
type UTC = number
Copy link
Owner

Choose a reason for hiding this comment

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

hmmm -- do we expect this test to output nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, sorry I missed this when running my tests. It was due to using the source path object instead of the Walkdir entry, tested again and should be working as expected.

@Wulf
Copy link
Owner

Wulf commented Dec 10, 2023

hey @aaronh-mood, thanks for taking the time to cleanup and add support for the rename directive 🙌 ! No disrespect taken, it's a community effort at the end of the day and we're all trying to make the rust ecosystem better in our spare times :-)

@aaronh-mood
Copy link
Contributor Author

aaronh-mood commented Dec 10, 2023

Thanks @Wulf! This was actually my first PR to a public repo, so I wasn't quite sure how it would be taken but I appreciate the nice reception and hopefully I can add some value to this project. Keep up the great work. This already helped me a great deal.

Copy link
Owner

@Wulf Wulf left a comment

Choose a reason for hiding this comment

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

awesome, thanks for addressing my concerns -- hope you had a great holiday season and happy new year :)

@Wulf Wulf merged commit 9f5b950 into Wulf:main Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants