Are re-exported types distinct from the original types?

Suppose crate a exports struct S, and crates b and c both depend on a and re-export S. Assuming b and c were built with the same version of a, will a crate d that depends on both b and c treat b::S and c::S as distinct types or the same type?

It will be treated as the same type.

This has interesting consequences regarding semantic versioning. Re-exporting types or traits from another crate (or implementing traits from another crate) conventionally makes this other crate a ‚Äúpublic dependency‚ÄĚ. So here, a would be a public dependency of b and c. If d also depends on a, then all three types: the a::S and the two re-exports b::S and c::C, will all be the same type. If a gets a major version update (not using the semver trick), then b and c cannot update their dependency to the newer version either without introducing a new major version, otherwise it would break users relying on the fact that the type from the specific version of a and the re-export from b or c are the same.

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.