rustrustdoc

How to make rustdoc link to private item from submodule?


I am documenting my binary project that is split to multiple submodules. I have two files in src/:

// src/main.rs

//! # My Lovely Crate
//! 
//! I can reference [`sub::Public`].
//! But, can't reference [`sub::Private`].

mod sub;

and

// src/sub.rs

//! # My Lovely Sub

/// This struct is public.
pub struct Public {
    a: usize,
}

/// This struct is private.
struct Private {
    b: usize,
}

When I run this with

cargo doc --document-private-items

The resulting docs are generated for both structures in sub, but the reference to sub::Private doesn't resolve—the link is not generated.

Is there a workaround? Or, am I doing something wrong?


Solution

  • Best workaround I have is to put a relative markdown link

    //! But, can't reference [`sub::Private`](sub/struct.Private.html).
    

    This should work in the simple case, but reexports or other complex cases might break it.