Something for which compiler support for sealed traits would be highly useful would be non-public methods in sealed traits.
For instance, I currently want to have a marker trait used in my library that’s used to restrict generic functions to some traits from my library. But these generic impls must now depend only on the interface of the marker trait, which means it has to export enough functions to be usable from said generic functions. And so these functions become part of the public API.
In code, here is what I’d like:
#[sealed]
trait Trait {
pub(crate) fn foo(&self);
}
struct Struct {}
impl Trait for Struct { fn foo(&self) {} }
fn bar<T: Trait>(t: &T) { t.foo() }
Does what I’m hoping for make sense? Currently the best way to do it appears to be #[doc(hidden)]… or defining a private struct in my library and taking it as an argument.
I don’t see any way other than sealed traits to do this cleanly, as pub(crate) would make no sense for non-sealed traits.