criterium/boolean/
direct_match.rs

1// SPDX-FileCopyrightText: 2025 Slatian
2//
3// SPDX-License-Identifier: LGPL-3.0-only
4
5//! Implements DirectMatch for the BooleanCriterium, doesn't export any functions
6
7use crate::boolean::BooleanCriterium;
8use crate::direct_match::DirectMatchResult;
9use crate::DirectMatch;
10
11impl DirectMatch<bool> for BooleanCriterium {
12	type Output = bool;
13
14	fn criterium_match(&self, data: &bool) -> bool {
15		match self {
16			Self::Equals(other) => data == other,
17			Self::IsNone => false,
18		}
19	}
20}
21
22impl<V> DirectMatch<Option<V>> for BooleanCriterium
23where
24	BooleanCriterium: DirectMatch<V>,
25{
26	type Output = <Self as DirectMatch<V>>::Output;
27
28	fn criterium_match(&self, data: &Option<V>) -> Self::Output {
29		match &data {
30			Some(data) => self.criterium_match(data),
31			None => Self::Output::new(matches!(self, Self::IsNone)),
32		}
33	}
34}