2

I am writing a documentation for crate and I noticed I am having lot's references like this:

/// A struct [`MyStruct`][`modA::subB::subC::MyStruct`] is very beautiful.

Is there a way to bring module subC into scope within the doc comment? It would be wonderful if I could write something like:

/// #[use modA::subB::subC::MyStruct];
/// A struct [`MyStruct`] is very beautiful.

Is there something like that?

Samuel Hapak
  • 6,950
  • 3
  • 35
  • 58

1 Answers1

1

I don't know if that's the best solution, but you can use a #[cfg(doc)] module that reexports the name:

pub mod super_long_a {
    pub mod super_long_b {
        pub mod super_long_c {
            pub struct Foo;
        }
    }
}

pub mod bar {
    #[cfg(doc)]
    mod doc_links {
        pub(super) use crate::super_long_a::super_long_b::super_long_c::Foo;
    }

    /// See [`Foo`](doc_links::Foo).
    pub fn qux() {}
}
Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77