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
205[[package]]205[[package]]
206name = "jrsonnet-types"206name = "jrsonnet-types"
207version = "0.3.3"207version = "0.3.3"
208dependencies = [
209 "peg",
210]
208211
209[[package]]212[[package]]
210name = "jsonnet"213name = "jsonnet"
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
1use crate::{1use crate::{
2 equals,2 equals,
3 error::{Error::*, Result},3 error::{Error::*, Result},
4 evaluate, parse_args, primitive_equals, push, throw,4 parse_args, primitive_equals, push, throw,
5 typed::CheckType,
6 with_state, ArrValue, Context, FuncVal, LazyVal, Val,5 with_state, ArrValue, Context, FuncVal, LazyVal, Val,
7};6};
8use format::{format_arr, format_obj};7use format::{format_arr, format_obj};
modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
146 ($ctx: expr, $fn_name: expr, $args: expr, $total_args: expr, [146 ($ctx: expr, $fn_name: expr, $args: expr, $total_args: expr, [
147 $($id: expr, $name: ident: $ty: expr $(=>$match: path)?);+ $(;)?147 $($id: expr, $name: ident: $ty: expr $(=>$match: path)?);+ $(;)?
148 ], $handler:block) => {{148 ], $handler:block) => {{
149 use $crate::{error::Error::*, throw, evaluate, push, typed::CheckType};
150
149 let args = $args;151 let args = $args;
150 if args.len() > $total_args {152 if args.len() > $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 {