style: format backend

This commit is contained in:
2026-01-03 23:57:50 +01:00
parent 7e10823714
commit 47d6d454e1
8 changed files with 52 additions and 26 deletions

View File

@@ -106,12 +106,12 @@ impl HealthStatus {
#[must_use]
pub fn record_error(self) -> Self {
match self {
Self::Healthy => Self::Degraded { consecutive_errors: 1 },
Self::Degraded { consecutive_errors } => {
Self::Degraded {
Self::Healthy => Self::Degraded {
consecutive_errors: 1,
},
Self::Degraded { consecutive_errors } => Self::Degraded {
consecutive_errors: consecutive_errors + 1,
}
}
},
Self::Unhealthy { reason } => Self::Unhealthy { reason },
}
}
@@ -161,7 +161,12 @@ mod tests {
assert!(!status.is_healthy());
assert!(status.is_degraded());
assert!(!status.is_unhealthy());
assert_eq!(status, HealthStatus::Degraded { consecutive_errors: 3 });
assert_eq!(
status,
HealthStatus::Degraded {
consecutive_errors: 3
}
);
}
#[test]
@@ -183,7 +188,12 @@ mod tests {
let status = HealthStatus::healthy();
let status = status.record_error();
assert!(status.is_degraded());
assert_eq!(status, HealthStatus::Degraded { consecutive_errors: 1 });
assert_eq!(
status,
HealthStatus::Degraded {
consecutive_errors: 1
}
);
}
#[test]
@@ -191,7 +201,12 @@ mod tests {
let status = HealthStatus::degraded(2);
let status = status.record_error();
assert!(status.is_degraded());
assert_eq!(status, HealthStatus::Degraded { consecutive_errors: 3 });
assert_eq!(
status,
HealthStatus::Degraded {
consecutive_errors: 3
}
);
}
#[test]
@@ -274,15 +289,30 @@ mod tests {
// Record first error -> Degraded with 1 error
let status = status.record_error();
assert!(status.is_degraded());
assert_eq!(status, HealthStatus::Degraded { consecutive_errors: 1 });
assert_eq!(
status,
HealthStatus::Degraded {
consecutive_errors: 1
}
);
// Record second error -> Degraded with 2 errors
let status = status.record_error();
assert_eq!(status, HealthStatus::Degraded { consecutive_errors: 2 });
assert_eq!(
status,
HealthStatus::Degraded {
consecutive_errors: 2
}
);
// Record third error -> Degraded with 3 errors
let status = status.record_error();
assert_eq!(status, HealthStatus::Degraded { consecutive_errors: 3 });
assert_eq!(
status,
HealthStatus::Degraded {
consecutive_errors: 3
}
);
// Mark unhealthy -> Unhealthy
let status = status.mark_unhealthy("Too many consecutive errors");

View File

@@ -35,6 +35,6 @@
//! - Type design: `specs/001-modbus-relay-control/types-design.md`
//! - Domain specification: `specs/001-modbus-relay-control/spec.md`
pub mod relay;
pub mod modbus;
pub mod health;
pub mod modbus;
pub mod relay;

View File

@@ -54,7 +54,6 @@ impl Relay {
pub fn label(&self) -> Option<RelayLabel> {
self.label.clone()
}
}
#[cfg(test)]

View File

@@ -3,11 +3,11 @@
//! This module contains the core domain logic for relay control and management,
//! including relay types, repository abstractions, and business rules.
/// Controller error types for relay operations.
pub mod controller;
/// Relay entity representing the relay aggregate.
pub mod entity;
/// Repository trait and error types for relay persistence.
pub mod repository;
/// Domain types for relay identification and control.
pub mod types;
/// Controller error types for relay operations.
pub mod controler;
/// Relay entity representing the relay aggregate.
pub mod entity;

View File

@@ -1,7 +1,7 @@
mod relayid;
mod relaystate;
mod relaylabel;
mod relaystate;
pub use relayid::RelayId;
pub use relaystate::RelayState;
pub use relaylabel::RelayLabel;
pub use relaystate::RelayState;

View File

@@ -1,4 +1,4 @@
use crate::domain::relay::controler::ControllerError;
use crate::domain::relay::controller::ControllerError;
/// Unique identifier for a relay in the system.
///
@@ -33,7 +33,6 @@ impl RelayId {
pub const fn as_u8(&self) -> u8 {
self.0
}
}
impl std::fmt::Display for RelayId {

View File

@@ -1,5 +1,3 @@
use std::fmt::Display;
use thiserror::Error;
/// Human-readable label for a relay.
@@ -15,7 +13,7 @@ pub enum RelayLabelError {
#[error("Label cannot be empty")]
Empty,
#[error("Label exceeds maximum length of 50 characters: {0}")]
TooLong(usize)
TooLong(usize),
}
impl RelayLabel {