docify/lib.rs
1//! Docify provides a simple set of rust macros, namely [`#[docify::export]`](`export`) and
2//! [`docify::embed!`](`embed`), that allow you to dynamically embed tests and examples at
3//! compile time from the current crate or sub-crates of the current crate directly within rust
4//! docs comments, with the option to make these examples runnable.
5//!
6//! The intent behind docify is to allow you to showcase your best examples and tests directly
7//! in your docs, without having to update them in two places every time there is a change. It
8//! also encourages a methodology where crate authors better document their tests, since they
9//! can now showcase these directly in their doc comments.
10//!
11//! All-in-all this is a much better workflow than having doc examples isolated within your docs,
12//! since you can avoid boilerplate from the surrounding code and just focus on showcasing the item
13//! you want to highlight.
14//!
15//! ## General Usage
16//!
17//! Using `docify` is simple. First mark the tests/examples/items that you wish to embed with
18//! `#[docify::export]`, such as the following:
19//!
20//! ```
21//! #[docify::export]
22//! fn some_example() {
23//! assert_eq!(2 + 2, 4);
24//! assert_eq!(2 + 3, 5);
25//! assert_eq!(3 + 3, 6);
26//! }
27//! ```
28//!
29//! You can then embed this item directly in doc comments using the `docify::embed` macro:
30//!
31//! ```
32//! /// These are some docs about an item. You can embed examples, tests, and
33//! /// other items directly into docs using the following macro:
34//! #[doc = docify::embed!("examples/samples.rs", some_example)]
35//! /// More docs can go here, the example will embed itself inline exactly
36//! /// where you reference it.
37//! pub struct SomeItem;
38//! ```
39//!
40//! This will result in the following expanded doc comments:
41//!
42//! ```
43//! /// These are some docs about an item. You can embed examples, tests, and
44//! /// other items directly into docs using the following macro:
45//! /// ```ignore
46//! /// fn some_example() {
47//! /// assert_eq!(2 + 2, 4);
48//! /// assert_eq!(2 + 3, 5);
49//! /// assert_eq!(3 + 3, 6);
50//! /// }
51//! /// ```
52//! /// More docs can go here, the example will embed itself inline exactly
53//! /// where you reference it.
54//! pub struct SomeItem;
55//! ```
56//!
57//! You can embed any item capable of having an attribute macro attached to it.
58//!
59//! ## Runnable Examples
60//!
61//! Note that you can also use the [`embed_run!`](`macro@embed_run`) version of the macro to
62//! make the embedded example compile/run as part of doc tests, which is desirable in certain
63//! situations even though typically the example will already be running/compiling somewhere
64//! else in your project.
65//!
66//! ## Dynamic Embedding in Markdown Files
67//!
68//! A newly added feature allows compiling entire directories of markdown files with HTML
69//! comments that contain regular [`docify::embed!`](`macro@embed`) calls. See
70//! [`compile_markdown!`](`macro@compile_markdown`) for more info.
71//!
72//! There is a live example of this as well in `README.md` where this same sentence appears in
73//! the root of the repo. `README.md` is dynamically generated when `cargo doc` is run based on
74//! the contents of `.README.docify.md`.
75#![no_std]
76
77pub use docify_macros::*;
78
79#[cfg(all(doc, feature = "generate-readme"))]
80compile_markdown!("README.docify.md", "README.md");