From 0971915a18928eea59545b2bd0be22befdb17a4f Mon Sep 17 00:00:00 2001 From: rodrimati1992 Date: Tue, 3 Dec 2024 18:20:29 -0300 Subject: [PATCH] Added doc examples to new BoolWitG methods Fixed changelog typo --- Changelog.md | 2 +- src/const_marker/boolwit.rs | 78 ++++++++++++++++++++++++++++++++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 906080f..601bd42 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,7 +14,7 @@ Added these methods to `BoolWitG`: - `unwrap_true` - `unwrap_false` -Relaxed `Copy + Clone + Debug` impls of `BooleanWitG` to work for any ` BooleanWitG`, instead of requirning ` BoolWitG>`. +Relaxed `Copy + Clone + Debug` impls of `BooleanWitG` to work for any ` BooleanWitG`, instead of requiring ` BoolWitG>`. ### 1.10.1 diff --git a/src/const_marker/boolwit.rs b/src/const_marker/boolwit.rs index 0dd2b59..3b3c658 100644 --- a/src/const_marker/boolwit.rs +++ b/src/const_marker/boolwit.rs @@ -203,45 +203,111 @@ pub enum BoolWitG { impl BoolWitG { /// Whether `B == Bool` + /// + /// # Example + /// + /// ```rust + /// use typewit::{const_marker::BoolWitG, TypeEq}; + /// + /// assert_eq!(BoolWitG::True(TypeEq::NEW).is_true(), true); + /// assert_eq!(BoolWitG::False(TypeEq::NEW).is_true(), false); + /// ``` + /// pub const fn is_true(self) -> bool { matches!(self, Self::True{..}) } /// Whether `B == Bool` + /// + /// # Example + /// + /// ```rust + /// use typewit::{const_marker::BoolWitG, TypeEq}; + /// + /// assert_eq!(BoolWitG::True(TypeEq::NEW).is_false(), false); + /// assert_eq!(BoolWitG::False(TypeEq::NEW).is_false(), true); + /// ``` + /// pub const fn is_false(self) -> bool { matches!(self, Self::False{..}) } /// Gets a proof of `B == Bool`, returns None if `B == Bool` + /// + /// # Example + /// + /// ```rust + /// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq}; + /// + /// assert_eq!(BoolWitG::True(TypeEq::NEW).to_true(), Some(TypeEq::new::>())); + /// assert_eq!(BoolWitG::False(TypeEq::NEW).to_true(), None); + /// ``` + /// pub const fn to_true(self) -> Option>> { match self { Self::True(x) => Some(x), - _ => None + Self::False{..} => None } } /// Gets a proof of `B == Bool`, returns None if `B == Bool` + /// + /// # Example + /// + /// ```rust + /// 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::>())); + /// ``` + /// pub const fn to_false(self) -> Option>> { match self { Self::False(x) => Some(x), - _ => None + Self::True{..} => None } } - /// Gets a proof of `B == Bool`, panics if `B == Bool` + /// Gets a proof of `B == Bool`. + /// + /// # Panic + /// + /// Panics if `B == Bool` + /// + /// # Example + /// + /// ```rust + /// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq}; + /// + /// assert_eq!(BoolWitG::False(TypeEq::NEW).unwrap_true(), TypeEq::new::>()); + /// ``` + /// pub const fn unwrap_true(self) -> TypeEq> { match self { Self::True(x) => x, - _ => panic!("attempted to unwrap into True on False variant") + Self::False{..} => panic!("attempted to unwrap into True on False variant") } } - /// Gets a proof of `B == Bool`, panics if `B == Bool` + /// Gets a proof of `B == Bool`. + /// + /// # Panic + /// + /// Panics if `B == Bool` + /// + /// # Example + /// + /// ```rust + /// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq}; + /// + /// assert_eq!(BoolWitG::False(TypeEq::NEW).unwrap_false(), TypeEq::new::>()); + /// ``` + /// pub const fn unwrap_false(self) -> TypeEq> { match self { Self::False(x) => x, - _ => panic!("attempted to unwrap into False on True variant") + Self::True{..} => panic!("attempted to unwrap into False on True variant") } }