Crates.io | derive-collect-docs |
lib.rs | derive-collect-docs |
version | 0.1.0 |
source | src |
created_at | 2020-03-26 16:07:46.2534 |
updated_at | 2020-03-26 16:07:46.2534 |
description | Collect documentation from Rust structs using a `CollectDocs` derive macro. |
homepage | |
repository | https://github.com/divvun/derive-collect-docs |
max_upload_size | |
id | 223154 |
size | 41,592 |
This little helper library contains a CollectDocs
derive macro.
Add it to your structs like this:
/// Very essential type to our application
#[example(
yaml,
"
bar: 42
baz:
great_examples_so_far: 2
"
)]
#[derive(Debug, serde::Deserialize, CollectDocs)]
pub struct Foo {
/// Amount of pressure to apply
///
/// CAUTION: Will be renamed to appropriate SI unit in next release.
pub bar: usize,
/// Description of this Foo
#[example(
yaml,
"
baz:
great_examples_so_far: 2
"
)]
pub baz: HashMap<String, i32>,
}
This will generate a AsciiDoc
file called Foo.adoc
(using the struct name).
By default this will be written to ./docs/generated
,
but you change it by setting the COLLECT_DOCS_TARGET
environment variable.
The rendered document looks like this and can be included in your AsciiDoc documentation.
Examples are added in separate attributes that specify the file type followed by the content. They will be included as code blocks with the heading "Example".
Examples in YAML format will also be turned into tests
that exercise that the given content can be parsed by
item the example is on.
For structs, you should give it the full content of the struct,
for fields you neded to also include the field name
in the formatting serde expects (i.e., respecting #[serde(rename="other_name")]
).
running 2 tests
test test_Foo_baz_example_0 ... ok
test test_Foo_example_0 ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
NOTE: You need to add both serde and serde_yaml to your own dependencies.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.