pub enum BoolWitG<B> {
True(TypeEq<B, Bool<true>>),
False(TypeEq<B, Bool<false>>),
}
Expand description
Type witness that B
is either Bool
<true>
or Bool
<false>
Use this over BoolWit
if you want to write a HasTypeWitness
bound
and adding a const B: bool
parameter would be impossible.
§Example
This basic example demonstrates where BoolWitG
would be used instead of BoolWit
.
use typewit::const_marker::{Bool, BoolWitG};
use typewit::HasTypeWitness;
trait Boolean: Sized + HasTypeWitness<BoolWitG<Self>> {
type Not: Boolean<Not = Self>;
}
impl Boolean for Bool<true> {
type Not = Bool<false>;
}
impl Boolean for Bool<false> {
type Not = Bool<true>;
}
Variants§
True(TypeEq<B, Bool<true>>)
Witnesses that B == true
False(TypeEq<B, Bool<false>>)
Witnesses that B == false
Implementations§
Source§impl<B> BoolWitG<B>
impl<B> BoolWitG<B>
Sourcepub const fn is_true(self) -> bool
pub const fn is_true(self) -> bool
Whether B == Bool<true>
§Example
use typewit::{const_marker::BoolWitG, TypeEq};
assert_eq!(BoolWitG::True(TypeEq::NEW).is_true(), true);
assert_eq!(BoolWitG::False(TypeEq::NEW).is_true(), false);
Sourcepub const fn is_false(self) -> bool
pub const fn is_false(self) -> bool
Whether B == Bool<false>
§Example
use typewit::{const_marker::BoolWitG, TypeEq};
assert_eq!(BoolWitG::True(TypeEq::NEW).is_false(), false);
assert_eq!(BoolWitG::False(TypeEq::NEW).is_false(), true);
Sourcepub const fn to_true(self) -> Option<TypeEq<B, Bool<true>>>
pub const fn to_true(self) -> Option<TypeEq<B, Bool<true>>>
Gets a proof of B == Bool<true>
, returns None if B == Bool<false>
§Example
use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
assert_eq!(BoolWitG::True(TypeEq::NEW).to_true(), Some(TypeEq::new::<Bool<true>>()));
assert_eq!(BoolWitG::False(TypeEq::NEW).to_true(), None);
Sourcepub const fn to_false(self) -> Option<TypeEq<B, Bool<false>>>
pub const fn to_false(self) -> Option<TypeEq<B, Bool<false>>>
Gets a proof of B == Bool<false>
, returns None if B == Bool<true>
§Example
use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
assert_eq!(BoolWitG::True(TypeEq::NEW).to_false(), None);
assert_eq!(BoolWitG::False(TypeEq::NEW).to_false(), Some(TypeEq::new::<Bool<false>>()));
Sourcepub const fn unwrap_true(self) -> TypeEq<B, Bool<true>>
pub const fn unwrap_true(self) -> TypeEq<B, Bool<true>>
Trait Implementations§
Source§impl<B> TypeWitnessTypeArg for BoolWitG<B>
impl<B> TypeWitnessTypeArg for BoolWitG<B>
impl<B> Copy for BoolWitG<B>
Auto Trait Implementations§
impl<B> Freeze for BoolWitG<B>
impl<B> RefUnwindSafe for BoolWitG<B>
impl<B> Send for BoolWitG<B>
impl<B> Sync for BoolWitG<B>
impl<B> Unpin for BoolWitG<B>
impl<B> UnwindSafe for BoolWitG<B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more