diff --git a/src/util/macros.rs b/src/util/macros.rs new file mode 100644 index 0000000..c5be1d8 --- /dev/null +++ b/src/util/macros.rs @@ -0,0 +1,5 @@ +#[macro_export] macro_rules! static_assert { + ($ex:expr) => { + const _: &[bool; ((($ex) == true) as usize)] = &[true]; + } +} diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 0000000..02b5fd3 --- /dev/null +++ b/src/util/mod.rs @@ -0,0 +1,17 @@ +#[allow(unused_imports)] +use std::{ + ops::{ + Drop, + Deref, + DerefMut, + }, + mem::{ + replace, + MaybeUninit, + }, + fmt, +}; + +#[macro_use] mod macros; pub use macros::*; +mod opaque; pub use opaque::*; +mod phantom_drop; pub use phantom_drop::*; diff --git a/src/util/opaque.rs b/src/util/opaque.rs new file mode 100644 index 0000000..73b658f --- /dev/null +++ b/src/util/opaque.rs @@ -0,0 +1,58 @@ +use super::*; + +/// Enabled `#[derive(Debug)]` on types with fields that are not `Debug`. +pub struct Opaque(T); + +impl Opaque +{ + /// Create a new `Opaque` wrapper around `value`. + #[inline] + pub const fn new(value: T) -> Self + { + Self(value) + } + + /// Consume `Opaque` and get back the inner value. + #[inline] + pub fn into(self) -> T + { + self.0 + } +} + +impl From for Opaque +{ + fn from(from: T) -> Self + { + Self(from) + } +} + +impl std::fmt::Debug for Opaque +{ + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + write!(f, "") + } +} + +impl Deref for Opaque +{ + type Target = T; + #[inline] + fn deref(&self) -> &Self::Target + { + &self.0 + } +} + + +impl DerefMut for Opaque +{ + #[inline] + fn deref_mut(&mut self) -> &mut ::Target + { + &mut self.0 + } +} diff --git a/src/util.rs b/src/util/phantom_drop.rs similarity index 70% rename from src/util.rs rename to src/util/phantom_drop.rs index c4bdb85..86c7244 100644 --- a/src/util.rs +++ b/src/util/phantom_drop.rs @@ -1,19 +1,6 @@ -#[allow(unused_imports)] -use std::{ - ops::{ - Drop, - Deref, - DerefMut, - }, - mem::{ - replace, - MaybeUninit, - }, - fmt, -}; +use super::*; use cfg_if::cfg_if; - #[cfg(not(debug_assertions))] type OptFn = MaybeUninit<(T,F)>; #[cfg(debug_assertions)] @@ -165,68 +152,3 @@ where F:FnOnce(T) } } - -/// Enabled `#[derive(Debug)]` on types with fields that are not `Debug`. -pub struct Opaque(T); - -impl Opaque -{ - /// Create a new `Opaque` wrapper around `value`. - #[inline] - pub const fn new(value: T) -> Self - { - Self(value) - } - - /// Consume `Opaque` and get back the inner value. - #[inline] - pub fn into(self) -> T - { - self.0 - } -} - -impl From for Opaque -{ - fn from(from: T) -> Self - { - Self(from) - } -} - -impl std::fmt::Debug for Opaque -{ - #[inline] - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result - { - write!(f, "") - } -} - -impl Deref for Opaque -{ - type Target = T; - #[inline] - fn deref(&self) -> &Self::Target - { - &self.0 - } -} - - -impl DerefMut for Opaque -{ - #[inline] - fn deref_mut(&mut self) -> &mut ::Target - { - &mut self.0 - } -} - -// static assert - -#[macro_export] macro_rules! static_assert { - ($ex:expr) => { - const _: &[bool; ((($ex) == true) as usize)] = &[true]; - } -}