/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/// A "trilean" value based on Kleen logic. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pubenum KleeneValue { /// False False = 0, /// True True = 1, /// Either true or false, but we’re not sure which yet.
Unknown,
}
impl From<bool> for KleeneValue { fn from(b: bool) -> Self { if b { Self::True
} else { Self::False
}
}
}
impl KleeneValue { /// Turns this Kleene value to a bool, taking the unknown value as an /// argument. pubfn to_bool(self, unknown: bool) -> bool { matchself { Self::True => true, Self::False => false, Self::Unknown => unknown,
}
}
/// Return true if any result of f() is true. Otherwise, return the strongest value seen. /// Returns false if empty, like that of `Iterator`. #[inline(always)] pubfn any<T>(
iter: impl Iterator<Item = T>,
f: impl FnMut(T) -> Self,
) -> Self { Self::any_value(iter, Self::True, Self::False, f)
}
/// Return false if any results of f() is false. Otherwise, return the strongest value seen. /// Returns true if empty, opposite of `Iterator`. #[inline(always)] pubfn any_false<T>(
iter: impl Iterator<Item = T>,
f: impl FnMut(T) -> Self,
) -> Self { Self::any_value(iter, Self::False, Self::True, f)
}
#[inline(always)] fn any_value<T>(
iter: impl Iterator<Item = T>,
value: Self,
on_empty: Self, mut f: impl FnMut(T) -> Self,
) -> Self { letmut result = None; for item in iter { let r = f(item); if r == value { return r;
} iflet Some(v) = result.as_mut() {
*v = *v & r;
} else {
result = Some(r);
}
}
result.unwrap_or(on_empty)
}
}
impl std::ops::Not for KleeneValue { type Output = Self;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.