diff --git a/crates/stackable-operator/src/kvp/key.rs b/crates/stackable-operator/src/kvp/key.rs index a7a6e079..9d606ba1 100644 --- a/crates/stackable-operator/src/kvp/key.rs +++ b/crates/stackable-operator/src/kvp/key.rs @@ -1,4 +1,9 @@ -use std::{fmt::Display, ops::Deref, str::FromStr, sync::LazyLock}; +use std::{ + fmt::{Debug, Display}, + ops::Deref, + str::FromStr, + sync::LazyLock, +}; use regex::Regex; use snafu::{ensure, ResultExt, Snafu}; @@ -56,12 +61,21 @@ pub enum KeyError { /// values. /// /// [k8s-labels]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Key { prefix: Option, name: KeyName, } +impl Debug for Key { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if let Some(prefix) = &self.prefix { + write!(f, "{:?}/", prefix)?; + } + write!(f, "{:?}", self.name) + } +} + impl FromStr for Key { type Err = KeyError; @@ -203,9 +217,15 @@ pub enum KeyPrefixError { /// [`Deref`], which enables read-only access to the inner value (a [`String`]). /// It, however, does not implement [`DerefMut`](std::ops::DerefMut) which would /// enable unvalidated mutable access to inner values. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct KeyPrefix(String); +impl Debug for KeyPrefix { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } +} + impl FromStr for KeyPrefix { type Err = KeyPrefixError; @@ -285,9 +305,15 @@ pub enum KeyNameError { /// which enables read-only access to the inner value (a [`String`]). It, /// however, does not implement [`DerefMut`](std::ops::DerefMut) which would /// enable unvalidated mutable access to inner values. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct KeyName(String); +impl Debug for KeyName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } +} + impl FromStr for KeyName { type Err = KeyNameError; diff --git a/crates/stackable-operator/src/kvp/label/value.rs b/crates/stackable-operator/src/kvp/label/value.rs index 2f8610e0..d1508d9e 100644 --- a/crates/stackable-operator/src/kvp/label/value.rs +++ b/crates/stackable-operator/src/kvp/label/value.rs @@ -1,4 +1,9 @@ -use std::{fmt::Display, ops::Deref, str::FromStr, sync::LazyLock}; +use std::{ + fmt::{Debug, Display}, + ops::Deref, + str::FromStr, + sync::LazyLock, +}; use regex::Regex; use snafu::{ensure, Snafu}; @@ -43,9 +48,15 @@ pub enum LabelValueError { /// unvalidated mutable access to inner values. /// /// [k8s-labels]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord)] pub struct LabelValue(String); +impl Debug for LabelValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } +} + impl Value for LabelValue { type Error = LabelValueError; } diff --git a/crates/stackable-operator/src/kvp/mod.rs b/crates/stackable-operator/src/kvp/mod.rs index c37ce71c..9131b9c8 100644 --- a/crates/stackable-operator/src/kvp/mod.rs +++ b/crates/stackable-operator/src/kvp/mod.rs @@ -2,7 +2,7 @@ //! key/value pairs, like labels and annotations. use std::{ collections::{BTreeMap, BTreeSet}, - fmt::Display, + fmt::{Debug, Display}, ops::Deref, str::FromStr, }; @@ -90,7 +90,7 @@ where /// /// - /// - -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct KeyValuePair where T: Value, @@ -99,6 +99,15 @@ where value: T, } +impl Debug for KeyValuePair +where + T: Value + Debug, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}: {:?}", self.key, self.value) + } +} + impl TryFrom<(K, V)> for KeyValuePair where K: AsRef,