feat(domain): implement Relay aggregate and RelayLabel newtype

Implemented the Relay aggregate as the primary domain entity for relay
control operations. Added RelayLabel newtype for validated human-readable
relay labels.

Relay aggregate features:
- Construction with id, state, and optional label
- State control methods: toggle(), turn_on(), turn_off()
- Accessor methods: id(), state(), label()
- All methods use const where possible for compile-time optimization

RelayLabel newtype features:
- Validation: non-empty, max 50 characters
- Smart constructor with Result-based error handling
- Default implementation: "Unlabeled"
- Transparent representation for zero-cost abstraction

Additional changes:
- Made RelayId derive Copy for ergonomic value semantics
- All public APIs include documentation and #[must_use] attributes

TDD phase: GREEN - Tests pass for Relay aggregate (T021 tests now pass)

Ref: T022, T024 (specs/001-modbus-relay-control/tasks.md)
This commit is contained in:
2026-01-03 23:33:21 +01:00
parent 72eafd285b
commit 6fc1fb834c
5 changed files with 111 additions and 8 deletions

View File

@@ -239,13 +239,13 @@
- **File**: src/domain/relay.rs
- **Complexity**: Low | **Uncertainty**: Low
- [ ] **T022** [US1] [TDD] Implement Relay aggregate
- Struct: Relay { id: RelayId, state: RelayState, label: Option<RelayLabel> }
- Methods: new(), toggle(), turn_on(), turn_off(), state(), label()
- [x] **T022** [US1] [TDD] Implement Relay aggregate
- Struct: `Relay { id: RelayId, state: RelayState, label: Option<RelayLabel> }`
- Methods: `new()` `toggle()` `turn_on()` `turn_off()` `state()` `label()`
- **File**: src/domain/relay.rs
- **Complexity**: Low | **Uncertainty**: Low
- [ ] **T023** [P] [US4] [TDD] Write tests for RelayLabel newtype
- [x] **T023** [P] [US4] [TDD] Write tests for RelayLabel newtype
- Test: RelayLabel::new("Pump") → Ok
- Test: RelayLabel::new("A".repeat(50)) → Ok
- Test: RelayLabel::new("") → Err(EmptyLabel)
@@ -253,7 +253,7 @@
- **File**: src/domain/relay.rs
- **Complexity**: Low | **Uncertainty**: Low
- [ ] **T024** [P] [US4] [TDD] Implement RelayLabel newtype
- [x] **T024** [P] [US4] [TDD] Implement RelayLabel newtype
- #[repr(transparent)] newtype wrapping String
- Constructor validates 1..=50 length
- Implement Display, Debug, Clone, PartialEq, Eq