aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Yuxuan Shui <yshuiv7@gmail.com>2020-09-16 02:04:05 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-09-16 11:49:16 +0200
commitba8a4f836c75dff63f026bd432d3a8659e5de394 (patch)
tree6f1c78ec50a0e1711344f6cdf7adf4220cbb05cd
parent17b9d06814cee84bfd57b73e1941b63187ec5f65 (diff)
downloadaskama-ba8a4f836c75dff63f026bd432d3a8659e5de394.tar.gz
askama-ba8a4f836c75dff63f026bd432d3a8659e5de394.tar.bz2
askama-ba8a4f836c75dff63f026bd432d3a8659e5de394.zip
fix into_f64 and into_isize
askama passes references to the filters (e.g. &f64), and &f64 doesn't implement NumCast, only f64 does. So, the filters should take &T instead of T. Fixes #357 Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
Diffstat (limited to '')
-rw-r--r--askama_shared/src/filters/mod.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/askama_shared/src/filters/mod.rs b/askama_shared/src/filters/mod.rs
index f203348..9a5b160 100644
--- a/askama_shared/src/filters/mod.rs
+++ b/askama_shared/src/filters/mod.rs
@@ -249,7 +249,7 @@ pub fn indent(s: &dyn fmt::Display, width: &usize) -> Result<String> {
#[cfg(feature = "num-traits")]
/// Casts number to f64
-pub fn into_f64<T>(number: T) -> Result<f64>
+pub fn into_f64<T>(number: &T) -> Result<f64>
where
T: NumCast,
{
@@ -258,7 +258,7 @@ where
#[cfg(feature = "num-traits")]
/// Casts number to isize
-pub fn into_isize<T>(number: T) -> Result<isize>
+pub fn into_isize<T>(number: &T) -> Result<isize>
where
T: NumCast,
{
@@ -460,22 +460,22 @@ mod tests {
#[test]
#[allow(clippy::float_cmp)]
fn test_into_f64() {
- assert_eq!(into_f64(1).unwrap(), 1.0 as f64);
- assert_eq!(into_f64(1.9).unwrap(), 1.9 as f64);
- assert_eq!(into_f64(-1.9).unwrap(), -1.9 as f64);
- assert_eq!(into_f64(INFINITY as f32).unwrap(), INFINITY);
- assert_eq!(into_f64(-INFINITY as f32).unwrap(), -INFINITY);
+ assert_eq!(into_f64(&1).unwrap(), 1.0 as f64);
+ assert_eq!(into_f64(&1.9).unwrap(), 1.9 as f64);
+ assert_eq!(into_f64(&-1.9).unwrap(), -1.9 as f64);
+ assert_eq!(into_f64(&(INFINITY as f32)).unwrap(), INFINITY);
+ assert_eq!(into_f64(&(-INFINITY as f32)).unwrap(), -INFINITY);
}
#[cfg(feature = "num-traits")]
#[test]
fn test_into_isize() {
- assert_eq!(into_isize(1).unwrap(), 1 as isize);
- assert_eq!(into_isize(1.9).unwrap(), 1 as isize);
- assert_eq!(into_isize(-1.9).unwrap(), -1 as isize);
- assert_eq!(into_isize(1.5 as f64).unwrap(), 1 as isize);
- assert_eq!(into_isize(-1.5 as f64).unwrap(), -1 as isize);
- match into_isize(INFINITY) {
+ assert_eq!(into_isize(&1).unwrap(), 1 as isize);
+ assert_eq!(into_isize(&1.9).unwrap(), 1 as isize);
+ assert_eq!(into_isize(&-1.9).unwrap(), -1 as isize);
+ assert_eq!(into_isize(&(1.5 as f64)).unwrap(), 1 as isize);
+ assert_eq!(into_isize(&(-1.5 as f64)).unwrap(), -1 as isize);
+ match into_isize(&INFINITY) {
Err(Fmt(fmt::Error)) => {}
_ => panic!("Should return error of type Err(Fmt(fmt::Error))"),
};