Created
August 1, 2017 23:01
-
-
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
This file contains 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_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 | |
} | |
}; | |
} |
This file contains 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
define_command! { | |
doc: "`Find` command.", | |
Find, { "F\0".to_string() }, 300 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.