# Rust Doc * [rust_doc](#rust_doc) * [rust_doc_test](#rust_doc_test) ## rust_doc
rust_doc(name, crate, html_after_content, html_before_content, html_in_header, markdown_css, rustc_flags, rustdoc_flags)Generates code documentation. Example: Suppose you have the following directory structure for a Rust library crate: ``` [workspace]/ WORKSPACE hello_lib/ BUILD src/ lib.rs ``` To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target: [rustdoc]: https://doc.rust-lang.org/book/documentation.html ```python package(default_visibility = ["//visibility:public"]) load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") rust_library( name = "hello_lib", srcs = ["src/lib.rs"], ) rust_doc( name = "hello_lib_doc", crate = ":hello_lib", ) ``` Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing the documentation for the `hello_lib` library crate generated by `rustdoc`. **ATTRIBUTES** | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | crate | The label of the target to generate code documentation for.
rust_doc_test(name, deps, crate)Runs Rust documentation tests. Example: Suppose you have the following directory structure for a Rust library crate: ```output [workspace]/ WORKSPACE hello_lib/ BUILD src/ lib.rs ``` To run [documentation tests][doc-test] for the `hello_lib` crate, define a `rust_doc_test` target that depends on the `hello_lib` `rust_library` target: [doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests ```python package(default_visibility = ["//visibility:public"]) load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test") rust_library( name = "hello_lib", srcs = ["src/lib.rs"], ) rust_doc_test( name = "hello_lib_doc_test", crate = ":hello_lib", ) ``` Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate. **ATTRIBUTES** | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | deps | List of other libraries to be linked to this library target.