use std::{format, string::String, vec::Vec};
use super::ClientKind;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum WarningSeverity {
Warning,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ConfigWarning {
pub severity: WarningSeverity,
pub client: ClientKind,
pub key: String,
pub message: String,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct WarningReport {
warnings: Vec<ConfigWarning>,
}
impl WarningReport {
#[must_use]
pub const fn new() -> Self {
Self {
warnings: Vec::new(),
}
}
pub fn push_unknown_key(&mut self, client: ClientKind, key: impl Into<String>) {
let key = key.into();
self.warnings.push(ConfigWarning {
severity: WarningSeverity::Warning,
client,
message: format!("unknown Kafka config key `{key}`"),
key,
});
}
pub fn push_java_only_key(&mut self, client: ClientKind, key: impl Into<String>, reason: &str) {
let key = key.into();
self.warnings.push(ConfigWarning {
severity: WarningSeverity::Warning,
client,
message: format!("Java-only Kafka config key `{key}` ignored: {reason}"),
key,
});
}
pub fn push_unsupported_feature(
&mut self,
client: ClientKind,
key: impl Into<String>,
feature: &str,
) {
let key = key.into();
self.warnings.push(ConfigWarning {
severity: WarningSeverity::Warning,
client,
message: format!("Kafka config key `{key}` requires feature `{feature}`"),
key,
});
}
#[must_use]
pub const fn warnings(&self) -> &[ConfigWarning] {
self.warnings.as_slice()
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.warnings.is_empty()
}
}