Add type-safe channel routing for UserOutput with newtype wrappers #137
+306
−38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Channel routing (stdout vs stderr) in
UserOutputwas done via runtime pattern matching. This adds compile-time guarantees using newtype wrappers to prevent accidental channel confusion.Changes
Type-Safe Wrappers (private)
StdoutWriterandStderrWriternewtypes wrappingBox<dyn Write + Send + Sync>new(),write_line(),writeln()UserOutput Structure
Box<dyn Write>to typed wrappers (stdout: StdoutWriter,stderr: StderrWriter)write_to_stdout()andwrite_to_stderr()for type-safe dispatchwrite()method now uses compile-time channel routing instead of runtime matchingExample
Before (runtime dispatch):
After (type-safe dispatch):
Compatibility
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
192.0.2.1ssh -i /nonexistent/key -p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=5 testuser@192.0.2.1 echo 'SSH connected'(packet block)ssh -i /nonexistent/key -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5 testuser@192.0.2.1 echo 'SSH connected'(packet block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Type-Safe Channel Routing for User Output</issue_title>
<issue_description>## Overview
Add compile-time type safety for channel routing (stdout vs stderr) in the
UserOutputmodule by introducing newtype wrappers for writers. Currently, channel routing is done with runtime pattern matching which, while functional, doesn't provide compile-time guarantees that messages go to the correct channel.This refactoring introduces
StdoutWriterandStderrWriternewtype wrappers that make channel routing explicit in the type system, preventing accidental channel confusion at compile time.Specification
See detailed specification: docs/issues/135-type-safe-channel-routing-for-user-output.md
🏗️ Architecture Requirements
DDD Layer: Presentation
Module Path:
src/presentation/user_output.rsPattern: Type-safe wrappers using newtype pattern
Module Structure Requirements
Architectural Constraints
Anti-Patterns to Avoid
Implementation Plan
Phase 1: Create Newtype Wrappers (30 minutes)
StdoutWriternewtype struct with documentationStderrWriternewtype struct with documentationnew()constructor for both wrapperswrite_line()method for both wrappersPhase 2: Update UserOutput Structure (45 minutes)
UserOutputstruct fields to use typed wrapperswrite_to_stdout()andwrite_to_stderr()write()method to use typed writer helpersPhase 3: Update Tests (30 minutes)
Phase 4: Documentation and Quality (30 minutes)
Acceptance Criteria
Quality Checks:
./scripts/pre-commit.shcargo testcargo doc --no-depsTask-Specific Criteria:
StdoutWriterandStderrWriternewtype wrappers are implementednew()andwrite_line()methodsUserOutputstruct uses typed wrappers instead of rawBox<dyn Write>write_to_stdout()andwrite_to_stderr()existwrite()method uses typed helpers instead of direct writer accessRelated
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.