Skip to content

Instantly share code, notes, and snippets.

@iamsebastian
Created October 27, 2016 11:01
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 iamsebastian/b3ac6d639b4e218f54cefe7549046c50 to your computer and use it in GitHub Desktop.
Save iamsebastian/b3ac6d639b4e218f54cefe7549046c50 to your computer and use it in GitHub Desktop.
Generate rust struct with documentation
macro_rules! generate_import_struct {
($doc:expr, name: $name:ident, $($element: ident: $ty: ty : $elem_doc: expr),*) => {
#[doc=$doc]
pub struct $name {
pub id: i32,
$(#[doc=$elem_doc]
pub $element: $ty),*
}
}
}
generate_import_struct!("Documentation of struct",
name: import_test,
test_field: String: "Just a test field",
another_field: i32: "Make integers happen"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment