This commit is contained in:
nora 2022-06-17 21:06:49 +02:00
commit bc58bda4a2
5 changed files with 55 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/target
/Cargo.lock
.idea
.vscode

11
Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[workspace]
members = [".", "accursed-unutterable-type-id-derive"]
[package]
name = "accursed-unutterable-type-id"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1,8 @@
[package]
name = "accursed-unutterable-type-id-derive"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1,14 @@
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);
}
}

18
src/lib.rs Normal file
View file

@ -0,0 +1,18 @@
/// A type that can be identified by a unique `AccursedUnutterableTypeId`.
///
/// # Safety
/// This trait is only allowed to be implemented by the derive macro.
pub unsafe trait AccursedUnutterablyTypeIdentified: 'static {
fn type_id() -> AccursedUnutterableTypeId;
}
pub struct AccursedUnutterableTypeId(u64);
impl AccursedUnutterableTypeId {
pub fn of<T>() -> Self
where
T: AccursedUnutterablyTypeIdentified,
{
T::type_id()
}
}