mirror of
https://github.com/Noratrieb/accursed-unutterable-type-id.git
synced 2026-01-14 08:35:02 +01:00
:corro:
This commit is contained in:
commit
bc58bda4a2
5 changed files with 55 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/target
|
||||
/Cargo.lock
|
||||
.idea
|
||||
.vscode
|
||||
11
Cargo.toml
Normal file
11
Cargo.toml
Normal 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]
|
||||
8
accursed-unutterable-type-id-derive/Cargo.toml
Normal file
8
accursed-unutterable-type-id-derive/Cargo.toml
Normal 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]
|
||||
14
accursed-unutterable-type-id-derive/src/lib.rs
Normal file
14
accursed-unutterable-type-id-derive/src/lib.rs
Normal 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
18
src/lib.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue