From 063f6edcc280ad62d643a0cd022fccf1cb6a869e Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Thu, 16 Nov 2023 12:13:22 +0100 Subject: Import 'predicates-core' crate Request Document: go/android-rust-importing-crates For CL Reviewers: go/android3p#cl-review For Build Team: go/ab-third-party-imports Bug: 310599818 Change-Id: I662dcdb358a1e058a7c2339e5fb9e4b54d2f7650 --- src/core.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/core.rs (limited to 'src/core.rs') diff --git a/src/core.rs b/src/core.rs new file mode 100644 index 0000000..b5aaa7b --- /dev/null +++ b/src/core.rs @@ -0,0 +1,32 @@ +// Copyright (c) 2018 The predicates-rs Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use crate::reflection; + +/// Trait for generically evaluating a type against a dynamically created +/// predicate function. +/// +/// The exact meaning of `eval` depends on the situation, but will usually +/// mean that the evaluated item is in some sort of pre-defined set. This is +/// different from `Ord` and `Eq` in that an `item` will almost never be the +/// same type as the implementing `Predicate` type. +pub trait Predicate: reflection::PredicateReflection { + /// Execute this `Predicate` against `variable`, returning the resulting + /// boolean. + fn eval(&self, variable: &Item) -> bool; + + /// Find a case that proves this predicate as `expected` when run against `variable`. + fn find_case<'a>(&'a self, expected: bool, variable: &Item) -> Option> { + let actual = self.eval(variable); + if expected == actual { + Some(reflection::Case::new(None, actual)) + } else { + None + } + } +} -- cgit v1.2.3