Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: manual traits are in prelude only #1111

Merged
merged 2 commits into from
Apr 26, 2021
Merged

docs: manual traits are in prelude only #1111

merged 2 commits into from
Apr 26, 2021

Conversation

bilelmoussaoui
Copy link
Member

fixes #1110

@MarijnS95
Copy link
Contributor

MarijnS95 commented Apr 24, 2021

I don't remember if this holds true for GStreamer-rs too...

EDIT: It does, but we also reexport these from the crate root.

@MarijnS95
Copy link
Contributor

@bilelmoussaoui Yup, looks good to me.

@sdroege Is it intended that we re-export some (but maybe not all?) traits from the crate root in addition to the prelude?

@sdroege
Copy link
Member

sdroege commented Apr 24, 2021

@sdroege Is it intended that we re-export some (but maybe not all?) traits from the crate root in addition to the prelude?

The non-manual traits are all exported from the crate root or not? I think we should re-export also the manual ones there...

@bilelmoussaoui
Copy link
Member Author

@sdroege Is it intended that we re-export some (but maybe not all?) traits from the crate root in addition to the prelude?

The non-manual traits are all exported from the crate root or not? I think we should re-export also the manual ones there...

pub use auto::traits::* is only used inside the prelude module. The same way for all the other crates, isn't that expected? otherwise the list of exports would be huge :)

@MarijnS95
Copy link
Contributor

@sdroege Is it intended that we re-export some (but maybe not all?) traits from the crate root in addition to the prelude?

The non-manual traits are all exported from the crate root or not? I think we should re-export also the manual ones there...

The non-manual traits are only exported from the prelude, as @bilelmoussaoui says pub use crate::auto::traits::*; is only inside pub mod prelude. However, it seems some (perhaps all, haven't checked this) ExtManual traits are exposed from the crate root. I'm just wondering if we should not do that and only reexport ExtManual from the prelude.

@sdroege
Copy link
Member

sdroege commented Apr 24, 2021

In that case yes, let's re-export all traits only from the prelude.

@MarijnS95
Copy link
Contributor

@sdroege That seems like quite a significant and breaking change, but perhaps for the better. More consistency when it comes to traits, I guess it doesn't make much sense to get the manual ones in the root and only get the autogenerated ones from the prelude only.

@MarijnS95
Copy link
Contributor

That was easier fixed than writing an actual commit message... https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/751

@sdroege
Copy link
Member

sdroege commented Apr 25, 2021

So that only affects GStreamer?

@bilelmoussaoui
Copy link
Member Author

So that only affects GStreamer?

From a quick look at the various gtk-rs repositories, seems like it

@MarijnS95
Copy link
Contributor

In gtk-rs auto/lib.rs also exports non-manual *Ext traits, which are reexported from the crate root through pub use crate::auto::*;.

Should we adapt gir to only leave these auto trait exports in mod traits {} so that they can be reexported from mod prelude only?

@bilelmoussaoui
Copy link
Member Author

In gtk-rs auto/lib.rs also exports non-manual *Ext traits, which are reexported from the crate root through pub use crate::auto::*;.

The discussion is about the manual traits though, no?

@MarijnS95
Copy link
Contributor

MarijnS95 commented Apr 25, 2021

Found one, TlsConnectionManualExt. That should be TlsConnectionExtManual if I'm not mistaken, and moved from lib.rs to mod prelude in gio, right?

The discussion is about the manual traits though, no?

Correct, but following https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/751#note_893338 we're also exploring what's going on with auto- (*Ext) traits, which AFAIK should only be exported from crate::auto::traits and crate::prelude, not from the crate root? Otherwise it makes little sense to only hide the manual implementations behind the prelude? Seems rather inconsistent to me.

EDIT: After all the difference between auto and manual is merely whether we can generate a correct function for it, that should be oblivious to crate users IMO.

@bilelmoussaoui
Copy link
Member Author

Found one, TlsConnectionManualExt. That should be TlsConnectionExtManual if I'm not mistaken, and moved from lib.rs to mod prelude in gio, right?

Yes, that's correct

Correct, but following https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/751#note_893338 we're also exploring what's going on with auto- (*Ext) traits, which AFAIK should only be exported from crate::auto::traits and crate::prelude, not from the crate root? Otherwise it makes little sense to only hide the manual implementations behind the prelude? Seems rather inconsistent to me.

Oh, I see what you mean now. We always re-export the non-manual traits indeed. Well, I don't know then, maybe we can just close this PR & we re-export everything.

MarijnS95 added a commit to MarijnS95/gtk3-rs that referenced this pull request Apr 25, 2021
Noticed in [1] that this trait has ManualExt written the wrong way
around, and is exported from the crate root instead of the prelude where
all other traits are reexported.

[1]: gtk-rs/gir#1111 (comment)
@MarijnS95
Copy link
Contributor

Oh, I see what you mean now. We always re-export the non-manual traits indeed. Well, I don't know then, maybe we can just close this PR & we re-export everything.

This PR is probably correct, but then we should make sure not to export any traits from the crate root. In my limited understanding ExtManual is merely containing functions that could not be represented by the generator (or in some cases extra functions that might be useful?). This split should be oblivious to crate users, hence we should either:

  • Remove *Ext exports from auto and keep everything within mod traits (reexported from mod prelude) only;
  • Reexport all traits, including manual ones, from the crate root to be consistent with reexported auto traits.

What do you think @bilelmoussaoui? @sdroege?

@sdroege
Copy link
Member

sdroege commented Apr 25, 2021

Yes it should be one of the two. What would be the advantage of re-exporting the traits from the crate root?

@MarijnS95
Copy link
Contributor

Yes it should be one of the two. What would be the advantage of re-exporting the traits from the crate root?

Less breakage for crates currently using Gtk/GStreamer and relying on those to be available when importing explicitly or * from the crate root? Other than that I don't see any. Either way, if we want to reexport from the crate root at some point we could use pub use crate::auto::traits::* anyway, if we go through with this cleanup the auto module wouldn't reexport the same traits twice at least.

MarijnS95 added a commit to MarijnS95/gtk3-rs that referenced this pull request Apr 25, 2021
Noticed in [1] that this trait has ManualExt written the wrong way
around, and is exported from the crate root instead of the prelude where
all other traits are reexported.

Besides, it has the name the correct way around in the `manual_traits`
array inside Gir.toml.

[1]: gtk-rs/gir#1111 (comment)
MarijnS95 added a commit to MarijnS95/gtk3-rs that referenced this pull request Apr 25, 2021
Noticed in [1] that this trait has ManualExt written the wrong way
around, and is exported from the crate root instead of the prelude where
all other traits are reexported.

Besides, it has the name the correct way around in the `manual_traits`
array inside Gir.toml.

[1]: gtk-rs/gir#1111 (comment)

Fixes: ad71d74 ("gio: manually generate get_channel_binding_data")
@bilelmoussaoui
Copy link
Member Author

I would go for having everything in prelude. Most of people don't really know the various traits there's and just want to call the method they want; having to look for the right trait & the module to import it from doesn't sound nice in practice. Also not re-exporting every trait in lib.rs would reduce the very large lib.rs docs page.

The user can still use a specific trait if they want by importing it from the module it comes from.

@sdroege
Copy link
Member

sdroege commented Apr 25, 2021 via email

@MarijnS95
Copy link
Contributor

MarijnS95 commented Apr 25, 2021

having to look for the right trait & the module to import it from doesn't sound nice in practice

That's not the intended usecase anyway, users should get use ...::prelude::*; and have everything available instead of randomly needing to import an extra *Ext from the crate root or just wildcard-import the entire gtk/gstreamer crate...

Also not re-exporting every trait in lib.rs would reduce the very large lib.rs docs page.

It would be very nice to have them nicely separated between types and their functions, indeed :)

I agree. Let's clean that up then

We have gtk-rs/gtk3-rs#483 for gtk-rs, https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/751 for GStreamer-rs, and let's get these exports removed from gir ASAP.

@bilelmoussaoui
Copy link
Member Author

Let's merge this one then, I will come with a MR (unless someone wants to take care of that) to remove the exported and only keep them in the auto::traits module (which is already used for re-exporting the traits from the prelude).

@MarijnS95
Copy link
Contributor

@bilelmoussaoui I think we need more documentation changes because now non-manual traits also come from prelude:: and not from the crate root anymore.

MarijnS95 added a commit to MarijnS95/gir that referenced this pull request Apr 25, 2021
Following a discussion in [1] we have decided to remove all trait
exports - both manual and automatic - from the crate root in favour of
having them available to crate users in `prelude` only, as per the
intended design.  It was inconsistent to have ExtManual traits available
in `prelude` only (and some randomly in the crate root in GStreamer-rs)
whereas all automatic traits were re-exported through the crate root as
well.

[1]: gtk-rs#1111
MarijnS95 added a commit to MarijnS95/gir that referenced this pull request Apr 25, 2021
Following a discussion in [1] we have decided to remove all trait
exports - both manual and automatic - from the crate root in favour of
having them available to crate users in `prelude` only, as per the
intended design.  It was inconsistent to have ExtManual traits available
in `prelude` only (and some randomly in the crate root in GStreamer-rs)
whereas all automatic traits were re-exported through the crate root as
well.

[1]: gtk-rs#1111
Copy link
Contributor

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected together with #1113, thanks!

This should go in first though, as it is always valid.

@sdroege sdroege merged commit 4ee43f3 into gtk-rs:master Apr 26, 2021
gstreamer-github pushed a commit to sdroege/gstreamer-rs that referenced this pull request Apr 26, 2021
In gir it was brought up [1] that some traits (in particular
`*ExtManual`) are exported from the crate root in addition to the
prelude, cluttering the environment unnecessarily.  This commit removes
all these reexports, leaving those in prelude (that were already there)
only.

After this commit everything matching `Ext(Manual)?\b` in `lib.rs` sits
within `pub mod prelude {};`.

[1]: gtk-rs/gir#1111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Links to ExtManual traits are broken
3 participants