Created
May 31, 2017 23:43
-
-
Save DmitrySoshnikov/ee758e84d51cc2b0a2741c04d52b1c91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
macro_rules! zoom_and_enhance { | |
(struct $name:ident { $($fname:ident : $ftype:ty),* }) => { | |
struct $name { | |
$($fname : $ftype),* | |
} | |
impl $name { | |
fn field_names() -> &'static [&'static str] { | |
static NAMES: &'static [&'static str] = &[$(stringify!($fname)),*]; | |
NAMES | |
} | |
} | |
} | |
} | |
zoom_and_enhance!{ | |
struct Export { | |
first_name: String, | |
last_name: String, | |
gender: String, | |
date_of_birth: String, | |
address: String | |
} | |
} | |
fn main() { | |
println!("{:?}", Export::field_names()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment