Skip to content

Instantly share code, notes, and snippets.

@saibatizoku
Created August 1, 2017 23:01
Show Gist options
  • Save saibatizoku/de8755c8add61607594bd4da4f96c3c6 to your computer and use it in GitHub Desktop.
Save saibatizoku/de8755c8add61607594bd4da4f96c3c6 to your computer and use it in GitHub Desktop.
macro that creates a command struct & impl with #[doc=...], with example of usage on another crate
#[macro_export]
macro_rules! define_command {
// DOCUMENTED COMMANDS
// ===================
// {
// doc: "docstring",
// Name, cmd_string_block, delay
// }
(doc: $doc:tt,
$name:ident, $command_string:block, $delay:expr) => {
#[doc=$doc]
define_command! {
$name, $command_string, $delay
}
};
// {
// doc: "docstring",
// Name, cmd_string_block, delay, Ack
// }
(doc: $doc:tt,
$name:ident, $command_string:block, $delay:expr, Ack) => {
#[doc=$doc]
define_command! {
$name, $command_string, $delay, Ack
}
};
}
define_command! {
doc: "`Find` command.",
Find, { "F\0".to_string() }, 300
}
@saibatizoku
Copy link
Author

Whenever the macro is used within the crate it is defined at, the #[doc="..."] attribute works fine, and the docstring shows fine when viewing the crate's documentation. However, when the macro is used from another crate, the docstring fails to show when generating the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment