#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum UpdateFeatureMode {
Upgrade,
SafeDowngrade,
UnsafeDowngrade,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct UpdateFeatureRef<'a> {
feature: &'a str,
max_version_level: i16,
mode: UpdateFeatureMode,
}
impl<'a> UpdateFeatureRef<'a> {
pub(crate) const fn new(
feature: &'a str,
max_version_level: i16,
mode: UpdateFeatureMode,
) -> Self {
Self {
feature,
max_version_level,
mode,
}
}
pub(crate) const fn feature(self) -> &'a str {
self.feature
}
pub(crate) const fn max_version_level(self) -> i16 {
self.max_version_level
}
pub(crate) const fn mode(self) -> UpdateFeatureMode {
self.mode
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct UpdateFeaturesRequestPlan<'a> {
updates: &'a [UpdateFeatureRef<'a>],
validate_only: bool,
}
impl<'a> UpdateFeaturesRequestPlan<'a> {
pub(crate) const fn new(updates: &'a [UpdateFeatureRef<'a>], validate_only: bool) -> Self {
Self {
updates,
validate_only,
}
}
pub(crate) const fn updates(self) -> &'a [UpdateFeatureRef<'a>] {
self.updates
}
pub(crate) const fn validate_only(self) -> bool {
self.validate_only
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct NormalizedUpdateFeaturesError {
code: i16,
message: Option<String>,
message_truncated: bool,
}
impl NormalizedUpdateFeaturesError {
pub(super) const fn new(code: i16, message: Option<String>, message_truncated: bool) -> Self {
Self {
code,
message,
message_truncated,
}
}
pub(crate) fn into_parts(self) -> (i16, Option<String>, bool) {
(self.code, self.message, self.message_truncated)
}
pub(super) fn retained_message_bytes(&self) -> usize {
self.message.as_ref().map_or(0, String::capacity)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct NormalizedUpdateFeatureResult {
feature: String,
error: Option<NormalizedUpdateFeaturesError>,
}
impl NormalizedUpdateFeatureResult {
pub(super) const fn new(feature: String, error: Option<NormalizedUpdateFeaturesError>) -> Self {
Self { feature, error }
}
pub(crate) fn into_parts(self) -> (String, Option<NormalizedUpdateFeaturesError>) {
(self.feature, self.error)
}
pub(super) fn retained_text_bytes(&self) -> Option<usize> {
self.feature.capacity().checked_add(
self.error
.as_ref()
.map_or(0, NormalizedUpdateFeaturesError::retained_message_bytes),
)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum NormalizedUpdateFeaturesOutcome {
TopLevelError(NormalizedUpdateFeaturesError),
Results(Vec<NormalizedUpdateFeatureResult>),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct NormalizedUpdateFeaturesResponse {
throttle_time_ms: u32,
outcome: NormalizedUpdateFeaturesOutcome,
retained_bytes: usize,
}
impl NormalizedUpdateFeaturesResponse {
pub(super) const fn new(
throttle_time_ms: u32,
outcome: NormalizedUpdateFeaturesOutcome,
retained_bytes: usize,
) -> Self {
Self {
throttle_time_ms,
outcome,
retained_bytes,
}
}
pub(crate) fn into_parts(self) -> (u32, NormalizedUpdateFeaturesOutcome, usize) {
(self.throttle_time_ms, self.outcome, self.retained_bytes)
}
}