-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
Add prelude for blanket and extension traits across sub-crates #1527
Conversation
ab59a65
to
10c5ed5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting this, I was about to write an issue for this!
Couple of things of-the-top of my head that could be useful:
kube-client/src/lib.rs
Outdated
//! | ||
//! The prelude may grow over time as additional items see ubiquitous use. | ||
|
||
#[cfg(feature = "unstable-client")] pub use crate::client::scope::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see people are importing traits in prelude using pub use ExplicitScope as _;
to presumably avoid warnings
https://github.com/tokio-rs/tracing/blob/master/tracing-subscriber/src/prelude.rs
ideally people should not need to opt-in to unused_imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure adding feature gates in a prelude is a good idea? People doing a wildcard import on prelude crate may get their symbols conditionally shadowed if another crate enabled this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the shadowing is a bigger problem than the feature gates, and the shadowing can be avoided by use X as _;
. It limits the prelude to extension trait stuff, but maybe that is a better way forward?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So as an update - I added all blanket implemented traits and extension traits to the prelude, while keeping those under feature gates separately - as prelude_unstable. I'm not sure that 2 preludes are needed, but went with separate so far. Also removed all struct, to avoid opt-in for unused imports. It would be perfect to have an option to say - prelude can be used but not re-exported (as in lib.rs), but I don't know if it is possible 🙂
347e05b
to
e8ed920
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1527 +/- ##
=====================================
Coverage 75.2% 75.2%
=====================================
Files 78 78
Lines 6989 6989
=====================================
Hits 5249 5249
Misses 1740 1740
|
eecd7b5
to
1136755
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some concerns.
e223729
to
ee5a2f5
Compare
@clux Should be fixed now, I removed everything causing a concern, leaving only subset of trait extensions. Also moved it to |
ee5a2f5
to
30d5fa3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks more appropriate. Two lines that can be avoided, but the exports there now are mostly sensible to me.
Signed-off-by: Danil-Grigorev <[email protected]>
30d5fa3
to
a2527ef
Compare
Added some better description, JIC someone returns to this. Thanks for the review @clux |
Motivation
Slight follow up on proposed changes in #1511 (comment)
Solution
Include prelude into
kube
crate, exporting all blanket implementations, such as:client::ConfigExt
- client configuration options.client::scope::NamespacedRef
- namespace scoped resource fetching viaclient.fetch
(underunstable-client
feature).core::PartialObjectMetaExt
- useful for cache size reduction in cases when only watched object type and metadata are required.core::crd::CustomResourceExt
- providing methods such as.crd()
for custom resource generation.core::crd::{Resource, ResourceExt}
- base and extension functionality on top of any valid kubernetes resource.runtime::utils::WatchStreamExt
- utility methods for watcher streams, providing predicate capabilities, stream sharing withreflect
andreflect_shared
(underruntime
feature)