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

difftreelog

feat unwrap_type macro

Yaroslav Bolyukin2021-01-25parent: #cebe933.patch.diff
in: master

4 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -205,6 +205,9 @@
 [[package]]
 name = "jrsonnet-types"
 version = "0.3.3"
+dependencies = [
+ "peg",
+]
 
 [[package]]
 name = "jsonnet"
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -1,8 +1,7 @@
 use crate::{
 	equals,
 	error::{Error::*, Result},
-	evaluate, parse_args, primitive_equals, push, throw,
-	typed::CheckType,
+	parse_args, primitive_equals, push, throw,
 	with_state, ArrValue, Context, FuncVal, LazyVal, Val,
 };
 use format::{format_arr, format_obj};
modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -146,6 +146,8 @@
 	($ctx: expr, $fn_name: expr, $args: expr, $total_args: expr, [
 		$($id: expr, $name: ident: $ty: expr $(=>$match: path)?);+ $(;)?
 	], $handler:block) => {{
+		use $crate::{error::Error::*, throw, evaluate, push, typed::CheckType};
+
 		let args = $args;
 		if args.len() > $total_args {
 			throw!(TooManyArgsFunctionHas($total_args));
modifiedcrates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth
8use jrsonnet_types::{ComplexValType, ValType};8use jrsonnet_types::{ComplexValType, ValType};
9use thiserror::Error;9use thiserror::Error;
10
11#[macro_export]
12macro_rules! unwrap_type {
13 ($desc: expr, $value: expr, $typ: expr => $match: path) => {{
14 use $crate::{push, typed::CheckType};
15 push(None, $desc, || Ok($typ.check(&$value)?))?;
16 match $value {
17 $match(v) => v,
18 _ => unreachable!(),
19 }
20 }}
21}
1022
11#[derive(Debug, Error, Clone)]23#[derive(Debug, Error, Clone)]
12pub enum TypeError {24pub enum TypeError {