Last active
August 14, 2018 23:41
-
-
Save passcod/1f16db3fefd130f2d0eec5a423dff78e 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
#![feature(custom_attribute)] | |
struct Something; | |
struct Bar; | |
trait SomeTrait { | |
type Result; | |
} | |
macro_rules! mac { | |
($some:ident, $my:ty, $mys:expr) => { | |
#[meta(result = $mys)] | |
struct $some; | |
impl SomeTrait<$some> for Something { | |
type Result = $my; | |
} | |
}; | |
($some:ident, $my:ty) => { | |
mac!($some, $my, stringify!($my)); | |
}; | |
} | |
mac!(Foo, Bar); |
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
#![feature(prelude_import)] | |
#![no_std] | |
#![feature(custom_attribute)] | |
#[prelude_import] | |
use std::prelude::v1::*; | |
#[macro_use] | |
extern crate std; | |
struct Something; | |
struct Bar; | |
trait SomeTrait { | |
type | |
Result; | |
} | |
macro_rules! mac(( $ some : ident , $ my : ty , $ mys : expr ) => { | |
# [ meta ( result = $ mys ) ] struct $ some ; impl SomeTrait | |
< $ some > for Something { type Result = $ my ; } } ; ( | |
$ some : ident , $ my : ty ) => { | |
mac ! ( $ some , $ my , stringify ! ( $ my ) ) ; } ;); | |
#[meta(result = "Bar")] | |
struct Foo; | |
impl SomeTrait<Foo> for Something { | |
type | |
Result | |
= | |
Bar; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment