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
d20fc815da
commit
dd85598b5c
3 changed files with 44 additions and 0 deletions
3
.rustfmt.toml
Normal file
3
.rustfmt.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
imports_granularity = "Crate"
|
||||
newline_style = "Unix"
|
||||
group_imports = "StdExternalCrate"
|
||||
27
accursed-unutterable-type-id-derive/src/lib.rs
Normal file
27
accursed-unutterable-type-id-derive/src/lib.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, DeriveInput};
|
||||
|
||||
#[proc_macro_derive(AccursedUnutterablyTypeIdentified)]
|
||||
pub fn my_macro(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
|
||||
let name = input.ident;
|
||||
|
||||
// SAFETY: We literally are the proc macro. and we have made sure that no duplicate type ids
|
||||
// will ever happen, right? :ferrisClueless:
|
||||
let expanded = quote! {
|
||||
unsafe impl ::accursed_unutterable_type_id::AccursedUnutterablyTypeIdentified for #name {
|
||||
fn type_id() -> ::accursed_unutterable_type_id::AccursedUnutterableTypeId {
|
||||
::accursed_unutterable_type_id::AccursedUnutterableTypeId(
|
||||
::accursed_unutterable_type_id::InternalAccursedUnutterableTypeId::new(
|
||||
0
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Hand the output tokens back to the compiler
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
14
examples/one.rs
Normal file
14
examples/one.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use accursed_unutterable_type_id::{AccursedUnutterableTypeId, AccursedUnutterablyTypeIdentified};
|
||||
|
||||
#[derive(AccursedUnutterablyTypeIdentified)]
|
||||
struct Uwu;
|
||||
|
||||
#[derive(AccursedUnutterablyTypeIdentified)]
|
||||
struct Owo;
|
||||
|
||||
fn main() {
|
||||
let uwu_id = AccursedUnutterableTypeId::of::<Uwu>();
|
||||
let owo_id = AccursedUnutterableTypeId::of::<Owo>();
|
||||
|
||||
assert_ne!(uwu_id, owo_id);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue