Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Created May 31, 2017 23:43
Show Gist options
  • Save DmitrySoshnikov/ee758e84d51cc2b0a2741c04d52b1c91 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/ee758e84d51cc2b0a2741c04d52b1c91 to your computer and use it in GitHub Desktop.
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