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

filters: escape arguments to pluralize at compile time #174

Merged
merged 6 commits into from
Sep 13, 2024

Conversation

Kijewski
Copy link
Collaborator

We can tell at compile time how to escape "" or "s". The former does not need to write anything, the latter does not need to be escaped.

@Kijewski Kijewski marked this pull request as draft September 13, 2024 11:34
@Kijewski Kijewski marked this pull request as ready for review September 13, 2024 11:44
buf.write(format_args!("{CRATE}::filters::pluralize("));
self._visit_arg(ctx, buf, count)?;
for value in [sg, pl] {
buf.write(", ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
buf.write(", ");
buf.write(',');

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

return None;
};
match kind {
Some(IntKind::I8) => is_signed_singular(i8::from_str_radix, value, 1, -1),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to think of a way to not have this huge match because it's very error prone to have to ensure that everything is working out correctly... Isn't it be possible somehow to have an impl with an associated type? Another (easier) way is to write a macro where we list types and then everything is generated correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a macro, but it's not much less ugly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed but at least less error-prone, well done!

Some(IntKind::I64) => is_signed_singular(i64::from_str_radix, value, 1, -1),
Some(IntKind::I128) => is_signed_singular(i128::from_str_radix, value, 1, -1),
Some(IntKind::Isize) => {
if cfg!(target_pointer_width = "16") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not doing isize::from_str_radix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The target and host pointer widths may be different.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, cross-compilation was the issue.

@GuillaumeGomez
Copy link
Contributor

Thanks for the improvement!

@GuillaumeGomez GuillaumeGomez merged commit 142a785 into rinja-rs:master Sep 13, 2024
34 checks passed
@Kijewski
Copy link
Collaborator Author

Thanks! :) Should have thought about that already in the first PR.

@Kijewski Kijewski deleted the pr-compile-time-pluralize branch September 13, 2024 16:20
@GuillaumeGomez
Copy link
Contributor

Well I definitely didn't think about that so that makes two of us.

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