Skip to content

Instantly share code, notes, and snippets.

@passcod
Last active August 14, 2018 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passcod/1f16db3fefd130f2d0eec5a423dff78e to your computer and use it in GitHub Desktop.
Save passcod/1f16db3fefd130f2d0eec5a423dff78e to your computer and use it in GitHub Desktop.
#![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);
#![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