Documentation generated for Rust Project includes Library Crate but excludes Binary Crate Root


#1

I am having difficulties applying the “Documentation” chapter of a Rust book.

A high-level view of how my project code is structured at the moment is shown in the below code snippets, whilst the entire repo is here, I can run all my Unit Tests with cargo test, and I can Build & Run the source code of both the ‘hello’ Binary Crate Root and ‘hello_world’ Library Crate that it imports from at the same time with cargo run and it all works successfully. However, when I run cargo docs it only generates and opens the HTML Documentation for the ‘hello_world’ Library Crate (without any HTML Documentation for the ‘hello’ Binary Crate Root as well), which is the Package in the Cargo.toml file. I can achieve the same outcome by explicitly running cargo doc --package hello_world --open to generate the same HTML Documentation for only the Library Crate “hello_world”.

What do I need to change so that I can create HTML Documentation for the ‘hello’ Binary Crate Root as well?

Ideally I just want to run cargo doc --open and for it to generate and open the HTML Documentation based on annotations in the source code of both the Binary Crate Root ‘hello’ (i.e. ./src/main.rs) and also the Crate Library ‘hello_world’ (./src/lib.rs).

The Cargo configuration file ./Cargo.toml shown below includes the Library Crate named “hello_world” (the Package) and the Binary Crate Root named “hello”.

[package] # Metadata about the package

# Library name
name = "hello_world"
version = "0.0.1"

[[bin]] # Informs Cargo Binary executable build outcome desired

# Binary executable name (differs from Library)
name = "hello"

The ./src/main.rs file is the Binary Crate Root named ‘hello’ and is structured as follows:

use std::old_io;

// Import 'hello_world' Library Crates' publicly accessible shapes Module into the scope of main.rs
use hello_world::shapes;

// Compile and link to the Library Crate named 'hello_world' so its Modules may be used in main.rs
extern crate hello_world;

fn main() {
    try_documentation();
}

/// ```
/// println!("Documentation Comments for main.rs are working if this is shown after running 'cargo doc'");
/// ```
fn try_documentation() {

}

The ./src/lib.rs file is the Library Crate named ‘hello_world’ and is structured as follows:

// Unit Tests
extern crate test;

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert!(true);
    }
}

pub mod shapes {
    // code omitted for brevity
}