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

clippy::needless_pass_by_value #654

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions minijinja-contrib/src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ pub use self::datetime::*;
/// ```jinja
/// {{ platypuses|length }} platypus{{ platypuses|pluralize(None, "es") }}.
/// ```
pub fn pluralize(v: Value, singular: Option<Value>, plural: Option<Value>) -> Result<Value, Error> {
pub fn pluralize(
v: &Value,
singular: Option<Value>,
plural: Option<Value>,
) -> Result<Value, Error> {
let is_singular = match v.len() {
Some(val) => val == 1,
None => match i64::try_from(v.clone()) {
Expand Down Expand Up @@ -70,7 +74,7 @@ pub fn pluralize(v: Value, singular: Option<Value>, plural: Option<Value>) -> Re
/// ```
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn random(state: &minijinja::State, seq: Value) -> Result<Value, Error> {
pub fn random(state: &minijinja::State, seq: &Value) -> Result<Value, Error> {
use crate::globals::get_rng;
use minijinja::value::ValueKind;
use rand::Rng;
Expand Down Expand Up @@ -163,7 +167,7 @@ pub fn filesizeformat(value: f64, binary: Option<bool>) -> String {
/// leeway=2
/// ) }}
/// ```
pub fn truncate(state: &State, value: Value, kwargs: Kwargs) -> Result<String, Error> {
pub fn truncate(state: &State, value: &Value, kwargs: Kwargs) -> Result<String, Error> {
if matches!(value.kind(), ValueKind::None | ValueKind::Undefined) {
return Ok("".into());
}
Expand Down Expand Up @@ -222,7 +226,7 @@ pub fn truncate(state: &State, value: Value, kwargs: Kwargs) -> Result<String, E
/// ```
#[cfg(feature = "wordcount")]
#[cfg_attr(docsrs, doc(cfg(feature = "wordcount")))]
pub fn wordcount(value: Value) -> Result<Value, Error> {
pub fn wordcount(value: &Value) -> Result<Value, Error> {
use unicode_categories::UnicodeCategories;

let s = value.as_str().unwrap_or_default();
Expand Down Expand Up @@ -257,7 +261,7 @@ pub fn wordcount(value: Value) -> Result<Value, Error> {
/// - `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<Value, Error> {
pub fn wordwrap(value: &Value, kwargs: Kwargs) -> Result<Value, Error> {
use textwrap::{wrap, Options as WrapOptions, WordSplitter};
let s = value.as_str().unwrap_or_default();

Expand Down
Loading