cfn-guard 3.2.0

AWS CloudFormation Guard is an open-source general-purpose policy-as-code evaluation tool. It provides developers with a simple-to-use, yet powerful and expressive domain-specific language (DSL) to define policies and enables developers to validate JSON- or YAML- formatted structured data with those policies.
Documentation
use crate::rules::{
    path_value::{Path, PathAwareValue},
    QueryResult,
};

pub(crate) fn count(args: &[QueryResult]) -> PathAwareValue {
    let count = args
        .iter()
        .filter(|query| !matches!(query, QueryResult::UnResolved(_)))
        .count();

    match args.is_empty() {
        true => PathAwareValue::Int((Path::root(), 0)),
        false => {
            let path = match &args[0] {
                QueryResult::Literal(val) | QueryResult::Resolved(val) => val.self_path().clone(),
                QueryResult::UnResolved(val) => val.traversed_to.self_path().clone(),
            };

            PathAwareValue::Int((path, count as i64))
        }
    }
}

#[cfg(test)]
#[path = "collections_tests.rs"]
mod collections_tests;