pub struct Bool<const D: bool = false>(pub bool);
Expand description
A bool
wrapper type that serializes true
and false
to "yes"
and "no"
respectively.
Bool
is generic over its default value D
.
See Bool::serialize
and Bool::deserialize
for how the default value D
is used to
serialize and deserialize empty/None
values.
§Examples
assert_eq!("yes", Bool::<false>::YES.as_str());
assert_eq!(Bool::<false>::NO, "no".parse().unwrap());
assert_eq!(Bool(true), Bool::<true>::default());
Tuple Fields§
§0: bool
Implementations§
Trait Implementations§
Source§impl<'de, const DEFAULT: bool> Deserialize<'de> for Bool<DEFAULT>
impl<'de, const DEFAULT: bool> Deserialize<'de> for Bool<DEFAULT>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserializes an empty value to Bool::<DEFAULT>::default()
, otherwise deserializes
from the string representation.
Source§impl<const D: bool> Ord for Bool<D>
impl<const D: bool> Ord for Bool<D>
Source§impl<const D: bool> PartialOrd for Bool<D>
impl<const D: bool> PartialOrd for Bool<D>
Source§impl<const D: bool> Serialize for Bool<D>
impl<const D: bool> Serialize for Bool<D>
Source§fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
Serializes Bool::<D>::default()
to None
, otherwise serializes the
string representation.
impl<const D: bool> Copy for Bool<D>
impl<const D: bool> Eq for Bool<D>
impl<const D: bool> StructuralPartialEq for Bool<D>
Auto Trait Implementations§
impl<const D: bool> Freeze for Bool<D>
impl<const D: bool> RefUnwindSafe for Bool<D>
impl<const D: bool> Send for Bool<D>
impl<const D: bool> Sync for Bool<D>
impl<const D: bool> Unpin for Bool<D>
impl<const D: bool> UnwindSafe for Bool<D>
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