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

Add int and float filters #146

Merged
merged 2 commits into from Nov 5, 2018
Merged

Add int and float filters #146

merged 2 commits into from Nov 5, 2018

Conversation

zzau13
Copy link
Contributor

@zzau13 zzau13 commented Nov 3, 2018

No description provided.

@tizgafa tizgafa force-pushed the master branch 3 times, most recently from 39edf7c to 7dce5de Compare November 3, 2018 19:00
@djc
Copy link
Owner

djc commented Nov 3, 2018

So do you have an actual use case for these, and if so, can you explain it to me a little?

@zzau13
Copy link
Contributor Author

zzau13 commented Nov 3, 2018

We have done it because they are listed in #18, but a practical case would be to truncate a float or cast int for operation with float. Per example:

{% for i in range %}
   {{ loop.index / (var_f32 | int) }}
   {{ (loop.index | float) / var_f32 }}
{% endfor %}

@@ -158,6 +161,14 @@ pub fn indent(s: &fmt::Display, width: &usize) -> Result<String> {
Ok(indented)
}

/// Casts number to i32
pub fn int<T>(number: T) -> Result<i32>
Copy link
Owner

Choose a reason for hiding this comment

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

So this is called int, but it casts to i32 -- which is kind of a random match. It could just as well be isize, usize, or u64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We adjust it to isize.

@@ -77,6 +78,14 @@ where
escape(i)
}

/// Casts number to f32
pub fn float<T>(number: T) -> Result<f32>
Copy link
Owner

Choose a reason for hiding this comment

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

Same issue here -- why f32, not f64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We adjust it to f64
.

@djc
Copy link
Owner

djc commented Nov 4, 2018

Hmm, so how about we call them into_isize and into_f64 then? I don't like those particular names that much, but I also think using the more generic int and float names for more-specific types feels wrong.

@zzau13
Copy link
Contributor Author

zzau13 commented Nov 5, 2018

With these more specific types we do some more, apart of into_isize and into_f64? into_i64 or into_usize...?

@djc
Copy link
Owner

djc commented Nov 5, 2018

If you have an actual use case for these today, we could do that. If you're satisfied with the first two, I'd prefer to keep it limited and further extend the collection as people come up with use cases.

@zzau13
Copy link
Contributor Author

zzau13 commented Nov 5, 2018

Done

@djc djc merged commit 962c24e into djc:master Nov 5, 2018
@djc
Copy link
Owner

djc commented Nov 5, 2018

Thanks, merged!

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.

None yet

3 participants