Skip to content

[WIP] aead: add doc_usage! macro #1945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions aead/src/doc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Documentation macros.
//!
//! These are used for writing redundant documentation that shows how to use the trait-based
//! interface with a concrete crate/type.

/// Write the "Usage" section of the toplevel documentation, using the given `$aead` type in
/// code examples.
#[doc(hidden)]
#[macro_export]
#[rustfmt::skip]
macro_rules! doc_usage {
($aead:ident) => {
concat!(
"# Usage\n",
"\n",
"Simple usage (allocating, no associated data):\n",
"\n",
"```\n",
"use ", env!("CARGO_CRATE_NAME"), "::{\n",
" aead::{Aead, AeadCore, KeyInit, rand_core::OsRng},\n",
" ", stringify!($aead), ", Nonce, Key\n",
"};\n",
"\n",
"// The encryption key can be generated randomly:\n",
"let key = ", stringify!($aead), "::generate_key().expect(\"generate key\");\n",
"```\n"
)
};
}
1 change: 1 addition & 0 deletions aead/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern crate alloc;

#[cfg(feature = "dev")]
pub mod dev;
mod doc;

pub use crypto_common::{
Key, KeyInit, KeySizeUser,
Expand Down