git.delta.rocks / jrsonnet / refs/commits / 6d535da7fe1f

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2021-07-06parent: #e668bf3.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -221,7 +221,7 @@
 		3, step: ty!((number | null));
 	], {
 		std_slice(
-			indexable.to_indexable()?,
+			indexable.into_indexable()?,
 			index.try_cast_nullable_num("index")?.map(|v| v as usize),
 			end.try_cast_nullable_num("end")?.map(|v| v as usize),
 			step.try_cast_nullable_num("step")?.map(|v| v as usize),
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -687,7 +687,7 @@
 				desc: &'static str,
 			) -> Result<Option<usize>> {
 				Ok(match expr {
-					Some(s) => evaluate(context.clone(), &s)?
+					Some(s) => evaluate(context.clone(), s)?
 						.try_cast_nullable_num(desc)?
 						.map(|v| v as usize),
 					None => None,
@@ -698,7 +698,7 @@
 			let end = parse_num(&context, desc.end.as_ref(), "end")?;
 			let step = parse_num(&context, desc.step.as_ref(), "step")?;
 
-			std_slice(indexable.to_indexable()?, start, end, step)?
+			std_slice(indexable.into_indexable()?, start, end, step)?
 		}
 		Import(path) => {
 			let tmp = loc
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	error::{Error::*, LocError, Result},3	throw, ObjValueBuilder, Val,4};5use serde_json::{Map, Number, Value};6use std::convert::{TryFrom, TryInto};78impl TryFrom<&Val> for Value {9	type Error = LocError;10	fn try_from(v: &Val) -> Result<Self> {11		Ok(match v {12			Val::Bool(b) => Self::Bool(*b),13			Val::Null => Self::Null,14			Val::Str(s) => Self::String((s as &str).into()),15			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {16				(*n as i64).into()17			} else {18				Number::from_f64(*n).expect("to json number")19			}),20			Val::Arr(a) => {21				let mut out = Vec::with_capacity(a.len());22				for item in a.iter() {23					out.push((&item?).try_into()?);24				}25				Self::Array(out)26			}27			Val::Obj(o) => {28				let mut out = Map::new();29				for key in o.fields() {30					out.insert(31						(&key as &str).into(),32						(&o.get(key)?.expect("field exists")).try_into()?,33					);34				}35				Self::Object(out)36			}37			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),38		})39	}40}4142impl From<&Value> for Val {43	fn from(v: &Value) -> Self {44		match v {45			Value::Null => Self::Null,46			Value::Bool(v) => Self::Bool(*v),47			Value::Number(n) => Self::Num(n.as_f64().expect("as f64")),48			Value::String(s) => Self::Str((s as &str).into()),49			Value::Array(a) => {50				let mut out: Vec<Val> = Vec::with_capacity(a.len());51				for v in a {52					out.push(v.into());53				}54				Self::Arr(out.into())55			}56			Value::Object(o) => {57				let mut builder = ObjValueBuilder::with_capacity(o.len());58				for (k, v) in o {59					builder.member((k as &str).into()).value(v.into());60				}61				Val::Obj(builder.build())62			}63		}64	}65}
after · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	error::{Error::*, LocError, Result},3	throw, ObjValueBuilder, Val,4};5use serde_json::{Map, Number, Value};6use std::convert::{TryFrom, TryInto};78impl TryFrom<&Val> for Value {9	type Error = LocError;10	fn try_from(v: &Val) -> Result<Self> {11		Ok(match v {12			Val::Bool(b) => Self::Bool(*b),13			Val::Null => Self::Null,14			Val::Str(s) => Self::String((s as &str).into()),15			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {16				(*n as i64).into()17			} else {18				Number::from_f64(*n).expect("to json number")19			}),20			Val::Arr(a) => {21				let mut out = Vec::with_capacity(a.len());22				for item in a.iter() {23					out.push((&item?).try_into()?);24				}25				Self::Array(out)26			}27			Val::Obj(o) => {28				let mut out = Map::new();29				for key in o.fields() {30					out.insert(31						(&key as &str).into(),32						(&o.get(key)?.expect("field exists")).try_into()?,33					);34				}35				Self::Object(out)36			}37			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),38		})39	}40}4142impl From<&Value> for Val {43	fn from(v: &Value) -> Self {44		match v {45			Value::Null => Self::Null,46			Value::Bool(v) => Self::Bool(*v),47			Value::Number(n) => Self::Num(n.as_f64().expect("as f64")),48			Value::String(s) => Self::Str((s as &str).into()),49			Value::Array(a) => {50				let mut out: Vec<Self> = Vec::with_capacity(a.len());51				for v in a {52					out.push(v.into());53				}54				Self::Arr(out.into())55			}56			Value::Object(o) => {57				let mut builder = ObjValueBuilder::with_capacity(o.len());58				for (k, v) in o {59					builder.member((k as &str).into()).value(v.into());60				}61				Self::Obj(builder.build())62			}63		}64	}65}
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -322,6 +322,11 @@
 		ObjValue::new(self.super_obj, Gc::new(self.map), Gc::new(self.assertions))
 	}
 }
+impl Default for ObjValueBuilder {
+	fn default() -> Self {
+		Self::with_capacity(0)
+	}
+}
 
 #[must_use = "value not added unless binding() was called"]
 pub struct ObjMemberBuilder<'v> {
@@ -332,8 +337,9 @@
 	location: Option<ExprLocation>,
 }
 
+#[allow(clippy::missing_const_for_fn)]
 impl<'v> ObjMemberBuilder<'v> {
-	pub fn with_add(mut self, add: bool) -> Self {
+	pub const fn with_add(mut self, add: bool) -> Self {
 		self.add = add;
 		self
 	}
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -571,7 +571,7 @@
 			.try_cast_str("to json")
 		})
 	}
-	pub fn to_indexable(self) -> Result<IndexableVal> {
+	pub fn into_indexable(self) -> Result<IndexableVal> {
 		Ok(match self {
 			Val::Str(s) => IndexableVal::Str(s),
 			Val::Arr(arr) => IndexableVal::Arr(arr),