git.delta.rocks / jrsonnet / refs/commits / fc51ec0b47cd

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2022-12-07parent: #ddc0d17.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
128 new_bindings,128 new_bindings,
129 )?;129 )?;
130 }130 }
131 Some(DestructRest::Drop) => {}131 Some(DestructRest::Drop) | None => {}
132 None => {}
133 }132 }
134133
202 .collect();201 .collect();
203 let full = Thunk::new(tb!(DataThunk {202 let full = Thunk::new(tb!(DataThunk {
204 parent,203 parent,
205 field_names: field_names.clone(),204 field_names,
206 has_rest: rest.is_some()205 has_rest: rest.is_some()
207 }));206 }));
208207
222 Ok(field)221 Ok(field)
223 } else {222 } else {
224 let (fctx, expr) = self.default.as_ref().expect("shape is checked");223 let (fctx, expr) = self.default.as_ref().expect("shape is checked");
225 Ok(evaluate(fctx.clone().unwrap(), &expr)?)224 Ok(evaluate(fctx.clone().unwrap(), expr)?)
226 }225 }
227 }226 }
228 }227 }
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -44,6 +44,8 @@
 extern crate self as jrsonnet_evaluator;
 
 mod arr;
+#[cfg(feature = "async-import")]
+pub mod async_import;
 mod ctx;
 mod dynamic;
 pub mod error;
@@ -188,6 +190,18 @@
 			evaluating: false,
 		}
 	}
+	pub(crate) fn get_string(&mut self) -> Option<IStr> {
+		if self.string.is_none() {
+			self.string = Some(
+				self.bytes
+					.as_ref()
+					.expect("either string or bytes should be set")
+					.clone()
+					.cast_str()?,
+			);
+		}
+		Some(self.string.clone().expect("just set"))
+	}
 }
 
 #[derive(Default, Trace)]
@@ -223,20 +237,9 @@
 				.1
 			}
 		};
-		if let Some(str) = &file.string {
-			return Ok(str.clone());
-		}
-		if file.string.is_none() {
-			file.string = Some(
-				file.bytes
-					.as_ref()
-					.expect("either string or bytes should be set")
-					.clone()
-					.cast_str()
-					.ok_or_else(|| ImportBadFileUtf8(path.clone()))?,
-			);
-		}
-		Ok(file.string.as_ref().expect("just set").clone())
+		Ok(file
+			.get_string()
+			.ok_or_else(|| ImportBadFileUtf8(path.clone()))?)
 	}
 	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise
 	pub fn import_resolved_bin(&self, path: SourcePath) -> Result<IBytes> {
@@ -288,23 +291,14 @@
 		if let Some(val) = &file.evaluated {
 			return Ok(val.clone());
 		}
-		if file.string.is_none() {
-			file.string = Some(
-				std::str::from_utf8(
-					file.bytes
-						.as_ref()
-						.expect("either string or bytes should be set"),
-				)
-				.map_err(|_| ImportBadFileUtf8(path.clone()))?
-				.into(),
-			);
-		}
-		let code = file.string.as_ref().expect("just set");
+		let code = file
+			.get_string()
+			.ok_or_else(|| ImportBadFileUtf8(path.clone()))?;
 		let file_name = Source::new(path.clone(), code.clone());
 		if file.parsed.is_none() {
 			file.parsed = Some(
 				jrsonnet_parser::parse(
-					code,
+					&code,
 					&ParserSettings {
 						source: file_name.clone(),
 					},