move util into directory

master
Avril 4 years ago
parent 260482290a
commit b07b68d587
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -0,0 +1,5 @@
#[macro_export] macro_rules! static_assert {
($ex:expr) => {
const _: &[bool; ((($ex) == true) as usize)] = &[true];
}
}

@ -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::*;

@ -0,0 +1,58 @@
use super::*;
/// Enabled `#[derive(Debug)]` on types with fields that are not `Debug`.
pub struct Opaque<T>(T);
impl<T> Opaque<T>
{
/// 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<T> From<T> for Opaque<T>
{
fn from(from: T) -> Self
{
Self(from)
}
}
impl<T> std::fmt::Debug for Opaque<T>
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "<opaque type>")
}
}
impl<T> Deref for Opaque<T>
{
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target
{
&self.0
}
}
impl<T> DerefMut for Opaque<T>
{
#[inline]
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target
{
&mut self.0
}
}

@ -1,19 +1,6 @@
#[allow(unused_imports)] use super::*;
use std::{
ops::{
Drop,
Deref,
DerefMut,
},
mem::{
replace,
MaybeUninit,
},
fmt,
};
use cfg_if::cfg_if; use cfg_if::cfg_if;
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
type OptFn<T,F> = MaybeUninit<(T,F)>; type OptFn<T,F> = MaybeUninit<(T,F)>;
#[cfg(debug_assertions)] #[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>(T);
impl<T> Opaque<T>
{
/// 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<T> From<T> for Opaque<T>
{
fn from(from: T) -> Self
{
Self(from)
}
}
impl<T> std::fmt::Debug for Opaque<T>
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "<opaque type>")
}
}
impl<T> Deref for Opaque<T>
{
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target
{
&self.0
}
}
impl<T> DerefMut for Opaque<T>
{
#[inline]
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target
{
&mut self.0
}
}
// static assert
#[macro_export] macro_rules! static_assert {
($ex:expr) => {
const _: &[bool; ((($ex) == true) as usize)] = &[true];
}
}
Loading…
Cancel
Save