-
-
Notifications
You must be signed in to change notification settings - Fork 223
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
Conversation
39edf7c
to
7dce5de
Compare
So do you have an actual use case for these, and if so, can you explain it to me a little? |
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:
|
askama_shared/src/filters/mod.rs
Outdated
@@ -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> |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
askama_shared/src/filters/mod.rs
Outdated
@@ -77,6 +78,14 @@ where | |||
escape(i) | |||
} | |||
|
|||
/// Casts number to f32 | |||
pub fn float<T>(number: T) -> Result<f32> |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
Hmm, so how about we call them |
With these more specific types we do some more, apart of |
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. |
Done |
Thanks, merged! |
They were added in <https://github.com/djc/askama/pull/146>. The example when they might be useful sounds contrived. You can always manually add the package `num-traits` to your project and use the methods directly. `into_isize` and `into_f64` wasn't even documented in the book.
No description provided.