From b0cb97cb36345bc42a95097ada82d6c015c14a55 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 10 Mar 2024 22:22:01 +0000 Subject: [PATCH] Stash WIP of future potential use of `#[diagnostic]` Signed-off-by: clux --- examples/dynamic_watcher.rs | 5 ++++- kube-core/src/lib.rs | 1 + kube-core/src/resource.rs | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/dynamic_watcher.rs b/examples/dynamic_watcher.rs index 9ab6753c6..5dc0c2a1c 100644 --- a/examples/dynamic_watcher.rs +++ b/examples/dynamic_watcher.rs @@ -8,6 +8,9 @@ use tracing::*; use std::{env, fmt::Debug}; +#[derive(Clone, Debug)] +struct MyStruct {} + #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); @@ -27,7 +30,7 @@ async fn main() -> anyhow::Result<()> { let (ar, _caps) = kube::discovery::pinned_kind(&client, &gvk).await?; // Use the full resource info to create an Api with the ApiResource as its DynamicType - let api = Api::::all_with(client, &ar); + let api = Api::::all_with(client, &ar); let wc = watcher::Config::default(); // Start a metadata or a full resource watch diff --git a/kube-core/src/lib.rs b/kube-core/src/lib.rs index a0371c169..cf90a0157 100644 --- a/kube-core/src/lib.rs +++ b/kube-core/src/lib.rs @@ -7,6 +7,7 @@ //! Everything in this crate is re-exported from [`kube`](https://crates.io/crates/kube) //! (even with zero features) under [`kube::core`]((https://docs.rs/kube/*/kube/core/index.html)). #![cfg_attr(docsrs, feature(doc_cfg))] +#![feature(diagnostic_namespace)] #![deny(missing_docs)] #![forbid(unsafe_code)] diff --git a/kube-core/src/resource.rs b/kube-core/src/resource.rs index 4b159b3bc..574eec42e 100644 --- a/kube-core/src/resource.rs +++ b/kube-core/src/resource.rs @@ -24,6 +24,12 @@ impl ResourceScope for DynamicResourceScope {} /// - `.metadata.resource_version` /// /// This avoids a bunch of the unnecessary unwrap mechanics for apps. +#[diagnostic::on_unimplemented( + message = "The `kube::Resource` trait is not implemented for `{Self}`", + label = "Is this type a `k8s-openapi` top level Kubernetes type, or a dynamic type created via `CustomResource`", + note = "If this is a CustomResource, please use the generated top level struct (not the spec struct) for `Api`", + note = "If this is a fully typed openapi struct, ensure you use the top-level resource type (e.g. `Pod` over `PodSpec`) for `Api`" +)] pub trait Resource { /// Type information for types that do not know their resource information at compile time. ///