Rustdoc - how to specify "canonical" item path?


#1

If you look at the std FromIterator trait, the word HashMap in the impl ... for HashMap links to the documentation of std::collections::HashMap, even though the actual definition is at std::collections::hash_map::HashMap, which is also visible in the online documentation.

I’m trying to recreate this in the documentation for my own crate, where I pub re-export MyStruct from a submodule using #[doc(inline)]. This works somewhat in the sense that the documentation page for MyStruct is generated in the right place. However, all of the links in the rest of the documentation to MyStruct point to the original definition, not the re-export. How can I make rustdoc link to the re-export?


#2

I think it might come down to the path used in the implementation? I.e. “use std::collections::HashMap; impl FromIterator for HashMap { … }” would link to std::collections::HashMap and “use std::collections::hash_map::HashMap; impl FromIterator for HashMap { … }” would link to std::collections::hash_map::HashMap.


#3

That doesn’t seem to have any effect.


#4

It’s actually defined in a private module hash::map and reexported in both places. So the module which defines MyStruct would need to be private.