Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[macro_export]
- macro_rules! my_macro {
- ($new_type:ident, $passed_type:ty => $body:expr) => {
- type $new_type = [$passed_type; 1];
- $body
- };
- }
- trait Trait<T> {
- fn trait_fn(&mut self) -> String;
- }
- struct Struct<T> {
- t: std::marker::PhantomData<T>,
- }
- impl<T> Trait<T> for Struct<T> {
- fn trait_fn(&mut self) -> String {
- my_macro! {
- A, T => {
- let x: A = [0];
- format!("{:?}", x)
- }
- }
- }
- }
- fn main() {
- let mut s = Struct::<u8> { t: std::marker::PhantomData };
- println!("{}", s.trait_fn());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement