use core::fmt;
mod translate;
pub(crate) use translate::translate_terminal;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum UpdateFeaturesDeliveryStatus {
NotSent,
PossiblySent,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UpdateFeaturesBrokerError {
pub(super) code: i16,
pub(super) message: Option<String>,
pub(super) message_truncated: bool,
}
impl UpdateFeaturesBrokerError {
pub const fn code(&self) -> i16 {
self.code
}
pub fn message(&self) -> Option<&str> {
self.message.as_deref()
}
pub const fn message_truncated(&self) -> bool {
self.message_truncated
}
pub fn into_parts(self) -> (i16, Option<String>, bool) {
(self.code, self.message, self.message_truncated)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum UpdateFeatureResult {
Updated,
Failed(UpdateFeaturesBrokerError),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UpdateFeatureOutcome {
pub(super) feature: String,
pub(super) result: UpdateFeatureResult,
}
impl UpdateFeatureOutcome {
pub fn feature(&self) -> &str {
&self.feature
}
pub const fn result(&self) -> &UpdateFeatureResult {
&self.result
}
pub fn into_parts(self) -> (String, UpdateFeatureResult) {
(self.feature, self.result)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UpdateFeaturesBatch {
pub(super) throttle_time_ms: u32,
pub(super) outcomes: Vec<UpdateFeatureOutcome>,
}
impl UpdateFeaturesBatch {
pub const fn throttle_time_ms(&self) -> u32 {
self.throttle_time_ms
}
pub fn outcomes(&self) -> &[UpdateFeatureOutcome] {
&self.outcomes
}
pub fn into_parts(self) -> (u32, Vec<UpdateFeatureOutcome>) {
(self.throttle_time_ms, self.outcomes)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum UpdateFeaturesFailureKind {
DeadlineElapsed,
DriverRejected,
Transport,
Broker(UpdateFeaturesBrokerError),
ResponseTooLarge,
Compatibility,
InvalidResponse,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UpdateFeaturesFailure {
pub(super) kind: UpdateFeaturesFailureKind,
pub(super) delivery: UpdateFeaturesDeliveryStatus,
}
impl UpdateFeaturesFailure {
pub const fn kind(&self) -> &UpdateFeaturesFailureKind {
&self.kind
}
pub const fn delivery(&self) -> UpdateFeaturesDeliveryStatus {
self.delivery
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum UpdateFeaturesOutcome {
Updated(UpdateFeaturesBatch),
Failed(UpdateFeaturesFailure),
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum UpdateFeaturesObserverError {
AlreadyObserved,
Stale,
}
impl fmt::Display for UpdateFeaturesObserverError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(match self {
Self::AlreadyObserved => "Admin UpdateFeatures result was already observed",
Self::Stale => "Admin UpdateFeatures observer is stale",
})
}
}
impl std::error::Error for UpdateFeaturesObserverError {}