Skip to content

Commit

Permalink
Add prelude for blanket and extension traits across sub-crates (#1527)
Browse files Browse the repository at this point in the history
Add blanket trait preludes for client, core and runtime lib

Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev authored Jul 15, 2024
1 parent 7a10e24 commit e57b060
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
34 changes: 20 additions & 14 deletions kube-client/src/client/client_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@ pub enum NamespaceError {
/// ```no_run
/// # use k8s_openapi::api::core::v1::Pod;
/// # use k8s_openapi::api::core::v1::Service;
/// # use kube::client::scope::{Cluster, Namespace};
/// # use kube::{ResourceExt, api::ListParams};
/// # use kube::client::scope::{Namespace, Cluster};
/// # use kube::prelude::*;
/// # use kube::api::ListParams;
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client: kube::Client = todo!();
/// let lp = ListParams::default();
Expand All @@ -264,8 +265,9 @@ impl Client {
/// ```no_run
/// # use k8s_openapi::api::rbac::v1::ClusterRole;
/// # use k8s_openapi::api::core::v1::Service;
/// # use kube::client::scope::{Cluster, Namespace};
/// # use kube::{ResourceExt, api::GetParams};
/// # use kube::client::scope::{Namespace, Cluster};
/// # use kube::prelude::*;
/// # use kube::api::GetParams;
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client: kube::Client = todo!();
/// let cr = client.get::<ClusterRole>("cluster-admin", &Cluster).await?;
Expand Down Expand Up @@ -296,8 +298,8 @@ impl Client {
/// # use k8s_openapi::api::core::v1::ObjectReference;
/// # use k8s_openapi::api::core::v1::LocalObjectReference;
/// # use k8s_openapi::api::core::v1::{Node, Pod};
/// # use kube::{Resource, ResourceExt, api::GetParams};
/// # use kube::client::scope::NamespacedRef;
/// # use kube::api::GetParams;
/// # use kube::prelude::*;
/// # use kube::api::DynamicObject;
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client: kube::Client = todo!();
Expand Down Expand Up @@ -355,8 +357,9 @@ impl Client {
/// ```no_run
/// # use k8s_openapi::api::core::v1::Pod;
/// # use k8s_openapi::api::core::v1::Service;
/// # use kube::client::scope::{Cluster, Namespace};
/// # use kube::{ResourceExt, api::ListParams};
/// # use kube::client::scope::{Namespace, Cluster};
/// # use kube::prelude::*;
/// # use kube::api::ListParams;
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client: kube::Client = todo!();
/// let lp = ListParams::default();
Expand Down Expand Up @@ -400,14 +403,17 @@ fn url_path(r: &ApiResource, namespace: Option<String>) -> String {

#[cfg(test)]
mod test {
use crate::client::client_ext::NamespacedRef;

use super::{
scope::{Cluster, Namespace},
Client, ListParams,
use crate::{
client::{
client_ext::NamespacedRef as _,
scope::{Cluster, Namespace},
},
Client,
};

use super::ListParams;
use k8s_openapi::api::core::v1::LocalObjectReference;
use kube_core::{DynamicObject, Resource, ResourceExt};
use kube_core::{DynamicObject, Resource as _, ResourceExt as _};

#[tokio::test]
#[ignore = "needs cluster (will list/get namespaces, pods, jobs, svcs, clusterroles)"]
Expand Down
6 changes: 3 additions & 3 deletions kube-runtime/src/utils/watch_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ impl<St: ?Sized> WatchStreamExt for St where St: Stream {}
#[cfg(feature = "unstable-runtime-predicates")]
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::predicates;
use futures::StreamExt;
use super::watcher;
use crate::{predicates, WatchStreamExt as _};
use futures::prelude::*;
use k8s_openapi::api::core::v1::Pod;
use kube_client::{Api, Resource};

Expand Down
23 changes: 23 additions & 0 deletions kube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,29 @@ pub use kube_core as core;
#[cfg(all(feature = "derive", feature = "runtime"))]
mod mock_tests;

pub mod prelude {
//! A "prelude" for kube client crate. Reduces the number of duplicated imports.
//!
//! This prelude is similar to the standard library's prelude in that you'll
//! almost always want to import its entire contents, but unlike the
//! standard library's prelude you'll have to do so manually:
//!
//! ```
//! use kube::prelude::*;
//! ```
//!
//! The prelude may grow over time as additional items see ubiquitous use.

#[allow(unreachable_pub)] pub use crate::client::ConfigExt as _;

#[cfg(feature = "unstable-client")] pub use crate::client::scope::NamespacedRef;

#[allow(unreachable_pub)] pub use crate::core::PartialObjectMetaExt as _;
pub use crate::{core::crd::CustomResourceExt as _, Resource as _, ResourceExt as _};

#[cfg(feature = "runtime")] pub use crate::runtime::utils::WatchStreamExt as _;
}

// Tests that require a cluster and the complete feature set
// Can be run with `cargo test -p kube --lib --features=runtime,derive -- --ignored`
#[cfg(test)]
Expand Down

0 comments on commit e57b060

Please sign in to comment.