diff --git a/minijinja-contrib/src/filters/mod.rs b/minijinja-contrib/src/filters/mod.rs index 257c0888..2fc34ab7 100644 --- a/minijinja-contrib/src/filters/mod.rs +++ b/minijinja-contrib/src/filters/mod.rs @@ -29,7 +29,11 @@ pub use self::datetime::*; /// ```jinja /// {{ platypuses|length }} platypus{{ platypuses|pluralize(None, "es") }}. /// ``` -pub fn pluralize(v: Value, singular: Option, plural: Option) -> Result { +pub fn pluralize( + v: &Value, + singular: Option, + plural: Option, +) -> Result { let is_singular = match v.len() { Some(val) => val == 1, None => match i64::try_from(v.clone()) { @@ -70,7 +74,7 @@ pub fn pluralize(v: Value, singular: Option, plural: Option) -> Re /// ``` #[cfg(feature = "rand")] #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] -pub fn random(state: &minijinja::State, seq: Value) -> Result { +pub fn random(state: &minijinja::State, seq: &Value) -> Result { use crate::globals::get_rng; use minijinja::value::ValueKind; use rand::Rng; @@ -163,7 +167,7 @@ pub fn filesizeformat(value: f64, binary: Option) -> String { /// leeway=2 /// ) }} /// ``` -pub fn truncate(state: &State, value: Value, kwargs: Kwargs) -> Result { +pub fn truncate(state: &State, value: &Value, kwargs: Kwargs) -> Result { if matches!(value.kind(), ValueKind::None | ValueKind::Undefined) { return Ok("".into()); } @@ -222,7 +226,7 @@ pub fn truncate(state: &State, value: Value, kwargs: Kwargs) -> Result Result { +pub fn wordcount(value: &Value) -> Result { use unicode_categories::UnicodeCategories; let s = value.as_str().unwrap_or_default(); @@ -257,7 +261,7 @@ pub fn wordcount(value: Value) -> Result { /// - `wrapstring`: String to join each wrapped line (default: newline) #[cfg(feature = "wordwrap")] #[cfg_attr(docsrs, doc(any(cfg(feature = "wordwrap"), cfg = "unicode_wordwrap")))] -pub fn wordwrap(value: Value, kwargs: Kwargs) -> Result { +pub fn wordwrap(value: &Value, kwargs: Kwargs) -> Result { use textwrap::{wrap, Options as WrapOptions, WordSplitter}; let s = value.as_str().unwrap_or_default();