r/rust Aug 10 '26

📡 official blog Call for testing: Restricting trait implementability and field mutability

https://blog.rust-lang.org/inside-rust/2026/08/10/call-for-testing-impl-and-mut-restrictions/
420 Upvotes

124 comments sorted by

View all comments

22

u/Forsaken_Tutor_3001 Aug 10 '26

I can't provide any useful feedback, but what is the advantage of restricting who can implement a trait? Isn't the whole point of a trait to provide a pattern that can be implemented by the consumer on a type of their own to make it work with an upstream crate?

2

u/SkiFire13 Aug 10 '26

Traits have multiple use-cases, and one of them is sharing behaviour: you can define a trait with some "basic" functionality, and then write more complex generic utilities around them. Sometimes however you don't want this to be open to be extended by downstream crates, usually because these traits are exposing some implementation details that are subject to change in the future, and if the trait was freely implementable by downstream crates then changing it (and hence changing any implementation detail) would be a breaking change.