mirror of
https://github.com/Noratrieb/accursed-unutterable-type-id.git
synced 2026-01-14 08:35:02 +01:00
why
This commit is contained in:
parent
bc58bda4a2
commit
d20fc815da
4 changed files with 49 additions and 15 deletions
|
|
@ -9,3 +9,4 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
accursed-unutterable-type-id-derive = { path = "./accursed-unutterable-type-id-derive" }
|
||||
|
|
@ -3,6 +3,11 @@ name = "accursed-unutterable-type-id-derive"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
quote = "1.0.18"
|
||||
syn = "1.0.96"
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
44
src/lib.rs
44
src/lib.rs
|
|
@ -1,3 +1,7 @@
|
|||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
pub use accursed_unutterable_type_id_derive::AccursedUnutterablyTypeIdentified;
|
||||
|
||||
/// A type that can be identified by a unique `AccursedUnutterableTypeId`.
|
||||
///
|
||||
/// # Safety
|
||||
|
|
@ -6,7 +10,45 @@ pub unsafe trait AccursedUnutterablyTypeIdentified: 'static {
|
|||
fn type_id() -> AccursedUnutterableTypeId;
|
||||
}
|
||||
|
||||
pub struct AccursedUnutterableTypeId(u64);
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct AccursedUnutterableTypeId(#[doc(hidden)] pub InternalAccursedUnutterableTypeId);
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[doc(hidden)]
|
||||
#[cfg(debug_assertions)]
|
||||
// we do a little trolling
|
||||
pub struct InternalAccursedUnutterableTypeId(u128, u64);
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[doc(hidden)]
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub struct InternalAccursedUnutterableTypeId(pub u64);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
impl InternalAccursedUnutterableTypeId {
|
||||
pub fn new(n: u64) -> Self {
|
||||
Self(0, n)
|
||||
}
|
||||
fn inner(self) -> u64 {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
impl InternalAccursedUnutterableTypeId {
|
||||
pub fn new(n: u64) -> Self {
|
||||
Self(n)
|
||||
}
|
||||
fn inner(self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for InternalAccursedUnutterableTypeId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Debug::fmt(&self.inner(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl AccursedUnutterableTypeId {
|
||||
pub fn of<T>() -> Self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue