diff --git a/aead/src/doc.rs b/aead/src/doc.rs new file mode 100644 index 000000000..3f90d1a36 --- /dev/null +++ b/aead/src/doc.rs @@ -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" + ) + }; +} diff --git a/aead/src/lib.rs b/aead/src/lib.rs index a1fbc5f84..9b565d75c 100644 --- a/aead/src/lib.rs +++ b/aead/src/lib.rs @@ -18,6 +18,7 @@ extern crate alloc; #[cfg(feature = "dev")] pub mod dev; +mod doc; pub use crypto_common::{ Key, KeyInit, KeySizeUser,