|
|
|
@ -135,7 +135,7 @@ pub type GenericID = uuid::Uuid;
|
|
|
|
|
($name:ident $(: $doc:literal)?) => ($crate::id_type!{pub(self) $name $(: $doc)?});
|
|
|
|
|
($vis:vis $name:ident $(: $doc:literal)?) => {
|
|
|
|
|
$(#[doc=$doc])?
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
|
|
|
|
$vis struct $name($crate::ext::GenericID);
|
|
|
|
|
|
|
|
|
|
impl $name
|
|
|
|
@ -187,12 +187,110 @@ pub type GenericID = uuid::Uuid;
|
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
|
#[cold] unreachable!()
|
|
|
|
|
} else {
|
|
|
|
|
unsafe { ::std::hint::unreachable_unchecked() }
|
|
|
|
|
::std::hint::unreachable_unchecked()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn a() -> !
|
|
|
|
|
|
|
|
|
|
/// Dirty debugging macro to get the compiler to print an error message telling you the size of a type.
|
|
|
|
|
/// ```
|
|
|
|
|
/// check_size!((u8, u8)); // Expected ... found one with *2* elements
|
|
|
|
|
/// ```
|
|
|
|
|
/// Can also be used to statically assert the size of a type
|
|
|
|
|
/// ```
|
|
|
|
|
/// # use datse::ext::check_size;
|
|
|
|
|
/// check_size!(u16 as 2; "u16 should be 2 bytes");
|
|
|
|
|
/// ```
|
|
|
|
|
#[macro_export] macro_rules! check_size {
|
|
|
|
|
($t:ty) => {
|
|
|
|
|
const _: [(); 0] = [(); ::std::mem::size_of::<$t>()];
|
|
|
|
|
};
|
|
|
|
|
($t:ty as $n:literal $(; $msg:literal)?) => {
|
|
|
|
|
const _: [(); $n] = [(); ::std::mem::size_of::<$t>()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Assert the output of a constant boolean expression is `true` at compile time.
|
|
|
|
|
#[macro_export] macro_rules! static_assert {
|
|
|
|
|
($val:expr $(; $msg:literal)?) => {
|
|
|
|
|
const _: [(); 1] = [(); ($val as bool) as usize];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Assert a trait is object safe. This will produce a compiler error if the trait is not object safe
|
|
|
|
|
#[macro_export] macro_rules! assert_object_safe {
|
|
|
|
|
($trait:path $(; $msg:literal)?) => {
|
|
|
|
|
const _:() = {
|
|
|
|
|
#[cold] fn __assert_object_safe() -> !
|
|
|
|
|
{
|
|
|
|
|
let _: &dyn $trait;
|
|
|
|
|
unsafe {
|
|
|
|
|
debug_unreachable!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert_object_safe!(AsRef<str>; "object safety assertion test");
|
|
|
|
|
static_assert!(1+1==2; "static assertion test");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub trait UnwrapInfallible<T>
|
|
|
|
|
{
|
|
|
|
|
fn unwrap_infallible(self) -> T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> UnwrapInfallible<T> for Result<T, std::convert::Infallible>
|
|
|
|
|
{
|
|
|
|
|
/// Unwrap with 0 overhead for values that cannot possibly be `Err`.
|
|
|
|
|
#[inline(always)] fn unwrap_infallible(self) -> T {
|
|
|
|
|
match self {
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
#[cold] Err(_) => unsafe { debug_unreachable!() },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(nightly)]
|
|
|
|
|
impl<T> UnwrapInfallible<T> for Result<T, !>
|
|
|
|
|
{
|
|
|
|
|
/// Unwrap with 0 overhead for values that cannot possibly be `Err`.
|
|
|
|
|
#[inline(always)] fn unwrap_infallible(self) -> T {
|
|
|
|
|
match self {
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
#[cold] Err(_) => unsafe { debug_unreachable!() },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub trait UnwrapErrInfallible<T>
|
|
|
|
|
{
|
|
|
|
|
fn unwrap_err_infallible(self) -> T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> UnwrapErrInfallible<T> for Result<std::convert::Infallible, T>
|
|
|
|
|
{
|
|
|
|
|
/// Unwrap with 0 overhead for values that cannot possibly be `Ok`.
|
|
|
|
|
#[inline(always)] fn unwrap_err_infallible(self) -> T {
|
|
|
|
|
match self {
|
|
|
|
|
Err(v) => v,
|
|
|
|
|
#[cold] Ok(_) => unsafe { debug_unreachable!() },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(nightly)]
|
|
|
|
|
impl<T> UnwrapErrInfallible<T> for Result<!, T>
|
|
|
|
|
{
|
|
|
|
|
debug_unreachable!()
|
|
|
|
|
/// Unwrap with 0 overhead for values that cannot possibly be `Ok`.
|
|
|
|
|
#[inline(always)] fn unwrap_err_infallible(self) -> T {
|
|
|
|
|
match self {
|
|
|
|
|
Err(v) => v,
|
|
|
|
|
#[cold] Ok(_) => unsafe { debug_unreachable!() },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|