Docs.rs Re-Exports vs Structs

Let's have a look at bincode on docs.rs. Then let's have a look at the Serializer and Deserializer structs. They are defined like this:

// in de/mod.rs
pub struct Deserializer<R, O: Options> {
    pub(crate) reader: R,
    options: O,
}
// in ser/mod.rs
pub struct Serializer<W, O: Options> {
    writer: W,
    _options: O,
}

Then they are re-exported like this:

// in lib.rs
pub use config::{Config, DefaultOptions, Options};
pub use de::read::BincodeRead;
pub use de::Deserializer;
pub use error::{Error, ErrorKind, Result};
pub use ser::Serializer;

So they are basically treated symmetrically. Nonetheless, if we look at the docs page, it shows Deserializer under "Re-exports" and Serializer under "Structs". Why is that?

The bincode::de module is public, so rustdoc can link bincode::Deserializer to bincode::de::Deserializer. However, the bincode::ser module is private (and thus not shown in rustdoc), so there’s nowhere for the export to link to, so Serializer gets inlined into the top-level crate docs.

Rustdoc inlining rules are documented in the rustdoc book.

3 Likes

Thanks!