Created
July 26, 2022 15:16
-
-
Save GoldsteinE/4b24e70639c1513e4bddfe5ebfa16ef2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Problem: | |
macro_rules! generate_impl { | |
($x:ident) => { | |
unsafe impl cxx::ExternType for $x { | |
// Won't work, `type_id!()` wants a literal, not a macro call | |
type Id = cxx::type_id!(stringify!($x)); | |
type Kind = cxx::kind::Trivial; | |
} | |
}; | |
} | |
// Solution: | |
macro_rules! generate_impl { | |
($x:ident) => { | |
::paste::paste! { | |
// `paste!()` concatenates strings with idents in doc comments | |
generate_impl!(@ $x #[doc = "" $x]); | |
} | |
}; | |
(@ $x:ident #[doc = $i:literal]) => { | |
unsafe impl cxx::ExternType for $x { | |
type Id = cxx::type_id!($i); | |
type Kind = cxx::kind::Trivial; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment