diff --git a/src/evaluator/functions.rs b/src/evaluator/functions.rs index 337cad45..c2ab1f52 100644 --- a/src/evaluator/functions.rs +++ b/src/evaluator/functions.rs @@ -1075,7 +1075,7 @@ pub fn fn_millis<'a>( // Turning the timestamp to a string given that the stable millis function // returns a u128 and the `Value::number` only supports f64. Ok(Value::string( - &context.arena, + context.arena, timestamp.as_millis().to_string().as_str(), )) } @@ -1087,7 +1087,7 @@ pub fn fn_uuid<'a>( max_args!(context, args, 0); Ok(Value::string( - &context.arena, + context.arena, Uuid::new_v4().to_string().as_str(), )) } diff --git a/src/evaluator/value.rs b/src/evaluator/value.rs index bd0cb194..f57f4175 100644 --- a/src/evaluator/value.rs +++ b/src/evaluator/value.rs @@ -37,7 +37,9 @@ pub const UNDEFINED: Value = Value::Undefined; pub const TRUE: Value = Value::Bool(true); pub const FALSE: Value = Value::Bool(false); -/// The core value type for input, output and evaluation. There's a lot of lifetimes here to avoid +/// The core value type for input, output and evaluation. +/// +/// There's a lot of lifetimes here to avoid /// cloning any part of the input that should be kept in the output, avoiding heap allocations for /// every Value, and allowing structural sharing. /// diff --git a/src/lib.rs b/src/lib.rs index 4ae94631..a969917f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ impl<'a> JsonAta<'a> { } fn json_value_to_value(&self, json_value: &serde_json::Value) -> &'a mut Value<'a> { - return match json_value { + match json_value { serde_json::Value::Null => Value::null(self.arena), serde_json::Value::Bool(b) => self.arena.alloc(Value::Bool(*b)), serde_json::Value::Number(n) => Value::number(self.arena, n.as_f64().unwrap()), @@ -65,16 +65,16 @@ impl<'a> JsonAta<'a> { array.push(self.json_value_to_value(v)) } - return array; + array } serde_json::Value::Object(o) => { let object = Value::object_with_capacity(self.arena, o.len()); for (k, v) in o.iter() { object.insert(k, self.json_value_to_value(v)); } - return object; + object } - }; + } } pub fn evaluate( @@ -219,7 +219,7 @@ mod tests { let jsonata = JsonAta::new("$map([1,4,9,16], $squareroot)", &arena).unwrap(); jsonata.register_function("squareroot", 1, |ctx, args| { let num = &args[0]; - return Ok(Value::number(ctx.arena, (num.as_f64()).sqrt())); + Ok(Value::number(ctx.arena, (num.as_f64()).sqrt())) }); let result = jsonata.evaluate(Some(r#"anything"#), None); @@ -240,7 +240,7 @@ mod tests { let jsonata = JsonAta::new("$filter([1,4,9,16], $even)", &arena).unwrap(); jsonata.register_function("even", 1, |_ctx, args| { let num = &args[0]; - return Ok(Value::bool((num.as_f64()) % 2.0 == 0.0)); + Ok(Value::bool((num.as_f64()) % 2.0 == 0.0)) }); let result = jsonata.evaluate(Some(r#"anything"#), None); diff --git a/tests/testsuite.rs b/tests/testsuite.rs index 906148f2..233cdc52 100644 --- a/tests/testsuite.rs +++ b/tests/testsuite.rs @@ -108,7 +108,7 @@ fn test_case(resource: &str) { } else if case["result_re"].is_string() { // Ability to define a regular expression to match the result. This strategy is useful // to validate the result of an expression that's not deterministic (like the $millis() function). - let regex_pattern = Regex::new(&case["result_re"].as_str().to_string()) + let regex_pattern = Regex::new(case["result_re"].as_str().as_ref()) .expect("Should have a valid regex expression"); assert!(