"Effective Rust", item 24

I do not really understand the following section:

As an aside, think carefully before using another crate's types in your API: it intimately ties your crate to that of the dependency. For example, a major version bump for the dependency (Item 21) will automatically require a major version bump for your crate too.

from Item 24: Re-export dependencies whose types appear in your API - Effective Rust

My problem is the "will automatically". Obviously, when my API uses a foreign data type, and that type's internal public structure changes for a mayor update of that crate, I might get a problem. But when that type does not change at all, or only the private internal structure changes, why should my crate and the users of my crate care, and why would my crate then require a major version bump?

Because they might have that older version of the crate installed.

For sanity, let's say their crate A uses your crate B v1 and you both use C v1, they previously could pass directly to their use of C your exported C types, but when you update your use of C to v2 without a B v2, A gets broken without making any changes because they now have two versions of C installed. If you instead publish a B v2, that will still break them without also updating you C v2, but that's expected and part of the semver contract.

3 Likes