stdont/primitive.rs
1/// Extensions for [`bool`].
2///
3/// See also [ACP #188](https://github.com/rust-lang/libs-team/issues/188)
4pub trait BoolExt {
5 /// Logical implication, equivalent to `!self || other`.
6 ///
7 /// ```rust
8 /// # use stdont::BoolExt as _;
9 /// assert!(false.implies(false));
10 /// assert!(false.implies(true));
11 /// assert!(!true.implies(false));
12 /// assert!(true.implies(true));
13 /// ```
14 #[must_use]
15 fn implies(self, other: Self) -> Self;
16
17 /// Inverse of [`.implies()`][BoolExt::implies].
18 ///
19 /// ```rust
20 /// # use stdont::BoolExt as _;
21 /// assert!(false.implied_by(false));
22 /// assert!(!false.implied_by(true));
23 /// assert!(true.implied_by(false));
24 /// assert!(true.implied_by(true));
25 /// ```
26 #[must_use]
27 fn implied_by(self, other: Self) -> Self;
28}
29
30impl BoolExt for bool {
31 #[inline]
32 fn implies(self, other: Self) -> Self {
33 !self || other
34 }
35
36 #[inline]
37 fn implied_by(self, other: Self) -> Self {
38 !other || self
39 }
40}