MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / resolve_val

Method resolve_val

cel/src/objects.rs:1006–1548  ·  view source on GitHub ↗
(
        expr: &'a Expression,
        ctx: &'a Context<'a>,
    )

Source from the content-addressed store, hash-verified

1004
1005 #[inline(always)]
1006 pub fn resolve_val<'a>(
1007 expr: &'a Expression,
1008 ctx: &'a Context<'a>,
1009 ) -> Result<Cow<'a, dyn Val>, ExecutionError> {
1010 match &expr.expr {
1011 Expr::Literal(literal) => Ok(literal.to_val()),
1012 Expr::Call(call) => {
1013 // START OF SPECIAL CASES FOR operators::...
1014 if call.args.len() == 3 && call.func_name == operators::CONDITIONAL {
1015 let cond = Value::resolve_val(&call.args[0], ctx);
1016 return if try_bool(cond)? {
1017 Value::resolve_val(&call.args[1], ctx)
1018 } else {
1019 Value::resolve_val(&call.args[2], ctx)
1020 };
1021 }
1022 if call.args.len() == 2 {
1023 match call.func_name.as_str() {
1024 operators::LOGICAL_OR => {
1025 let left = try_bool(Value::resolve_val(&call.args[0], ctx));
1026 return if Ok(true) == left {
1027 Ok(Cow::<dyn Val>::Owned(Box::new(CelBool::from(true))))
1028 } else {
1029 let right = Value::resolve_val(&call.args[1], ctx)?
1030 .downcast_ref::<CelBool>()
1031 .map(|b| *b.inner());
1032 match (left, right) {
1033 (Ok(false), Some(right)) => {
1034 Ok(Cow::<dyn Val>::Owned(Box::new(CelBool::from(right))))
1035 }
1036 (Err(_), Some(true)) => {
1037 Ok(Cow::<dyn Val>::Owned(Box::new(CelBool::from(true))))
1038 }
1039 (left, _) => Err(left.err().unwrap_or(NoSuchOverload)),
1040 }
1041 };
1042 }
1043 operators::LOGICAL_AND => {
1044 let left = try_bool(Value::resolve_val(&call.args[0], ctx));
1045 return if Ok(false) == left {
1046 Ok(Cow::<dyn Val>::Owned(Box::new(CelBool::from(false))))
1047 } else {
1048 let right = Value::resolve_val(&call.args[1], ctx)?
1049 .downcast_ref::<CelBool>()
1050 .map(|b| *b.inner());
1051 match (left, right) {
1052 (Ok(true), Some(right)) => {
1053 Ok(Cow::<dyn Val>::Owned(Box::new(CelBool::from(right))))
1054 }
1055 (Err(_), Some(false)) => {
1056 Ok(Cow::<dyn Val>::Owned(Box::new(CelBool::from(false))))
1057 }
1058 (left, _) => Err(left.err().unwrap_or(NoSuchOverload)),
1059 }
1060 };
1061 }
1062 operators::EQUALS => {
1063 return Ok(bool(

Callers

nothing calls this directly

Calls 15

try_boolFunction · 0.85
boolFunction · 0.85
to_valMethod · 0.80
mapMethod · 0.80
kindMethod · 0.80
try_intoMethod · 0.80
envMethod · 0.80
get_functionMethod · 0.80
cloneMethod · 0.80
find_member_overloadMethod · 0.80
get_variableMethod · 0.80
new_inner_scopeMethod · 0.80

Tested by

no test coverage detected