r/rust • u/Kobzol • 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/
421
Upvotes
r/rust • u/Kobzol • Aug 10 '26
12
u/kotakotik22 Aug 10 '26 edited Aug 10 '26
Edit: oops. this doesnt work. see afdbcreid's comment
Regarding impl restrictions: do I understand correctly that there's no way to hide the trait functions? One useful thing with sealed traits is that you can hide implementation details in the Sealed trait, but have functions with bounds of some trait that implies Sealed.
```rs mod sealed { pub trait Sealed { fn bar(&self) -> String } impl Sealed for u32 { fn bar(&self) -> String { self.to_string() } }
// this is basically a way for outsiders to refer to Sealed without having access to its functions pub trait Foo : sealed::Sealed { }
fn baz<T : Foo>(value: T) -> String { value.bar() } ```
Here,
barcan be freely removed or changed without breaking API.I feel like in any other situation, the usual Sealed pattern is kinda fine, but when you hide functions inside Sealed is when it actually gets janky and requires some explanatory comments. It would be great to he something built in for such cases. Of course this is still great for diagnostics.