gtk-rs-core
gtk-rs-core copied to clipboard
[BUG] The private struct is exposed with `ObjectSubclassIsExt::imp`
Bug description
Before ObjectSubclassIsExt::imp, the private struct would only be exposed when explicitly allowed to. Now, it can be accessed publicly, even from a different module.
Exposing the private struct may be okay on applications, but not on public API's
Also before the private struct was exported via that trait, see
https://github.com/gtk-rs/gtk-rs-core/blob/7cfcc209b46c54730293a6c0387bbc57524b80bc/glib/src/wrapper.rs#L437-L439
I'm quite sure the compiler was complaining if you didn't mark it as public, and because the from_instance() comes from a public trait you could already do exactly the same before.
I think it would only be possible before if the private struct is also public?
But it would have to be always public because it was leaked via the associated type. You could have done <YourPublicType as ObjectSubclassIs>::Subclass::from_instance() in the worst case, but I think the compiler even gave you an error because otherwise the private typed was leaked as public API.
I agree this isn't ideal if it can be avoided (which may be difficult with all the trait magic going on). But the harm seems limited if the private struct has no public members.
Note that if you mark all your private struct items as pub(super) you cannot access them from a different file even if you had access to the private struct through the imp method.