diff options
Diffstat (limited to 'vendor/zerovec/src/ule/option.rs')
-rw-r--r-- | vendor/zerovec/src/ule/option.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/vendor/zerovec/src/ule/option.rs b/vendor/zerovec/src/ule/option.rs index a6b1966a5..50b193aac 100644 --- a/vendor/zerovec/src/ule/option.rs +++ b/vendor/zerovec/src/ule/option.rs @@ -32,7 +32,7 @@ use core::mem::{self, MaybeUninit}; pub struct OptionULE<U>(bool, MaybeUninit<U>); impl<U: Copy> OptionULE<U> { - /// Obtain this as an Option<T> + /// Obtain this as an `Option<T>` pub fn get(self) -> Option<U> { if self.0 { unsafe { @@ -44,7 +44,7 @@ impl<U: Copy> OptionULE<U> { } } - /// Construct an OptionULE<U> from an equivalent Option<T> + /// Construct an `OptionULE<U>` from an equivalent `Option<T>` pub fn new(opt: Option<U>) -> Self { if let Some(inner) = opt { Self(true, MaybeUninit::new(inner)) @@ -54,6 +54,12 @@ impl<U: Copy> OptionULE<U> { } } +impl<U: Copy + core::fmt::Debug> core::fmt::Debug for OptionULE<U> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + self.get().fmt(f) + } +} + // Safety (based on the safety checklist on the ULE trait): // 1. OptionULE does not include any uninitialized or padding bytes. // (achieved by `#[repr(packed)]` on a struct containing only ULE fields, @@ -152,6 +158,12 @@ impl<U: VarULE + ?Sized> OptionVarULE<U> { } } +impl<U: VarULE + ?Sized + core::fmt::Debug> core::fmt::Debug for OptionVarULE<U> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + self.as_ref().fmt(f) + } +} + // Safety (based on the safety checklist on the VarULE trait): // 1. OptionVarULE<T> does not include any uninitialized or padding bytes // (achieved by being repr(packed) on ULE types) |