Skip to main content

netspeed_cli/
output.rs

1//! Output handling trait for extensibility.
2//!
3//! Enables different output strategies and testing.
4
5use crate::error::Error;
6use crate::types::TestResult;
7
8/// Trait for handling test results output.
9///
10/// Enables dependency injection for different output strategies
11/// and easier testing.
12pub trait OutputHandler: Send + Sync {
13    /// Handle a completed test result.
14    fn handle_result(&self, result: &TestResult) -> Result<(), Error>;
15
16    /// Handle an error during testing.
17    fn handle_error(&self, error: &Error) -> Result<(), Error>;
18}
19
20/// Default handler that outputs to terminal using formatter.
21pub struct DefaultOutputHandler {
22    _format: crate::config::Format,
23    _bytes_mode: bool,
24}
25
26impl DefaultOutputHandler {
27    pub fn new(format: crate::config::Format, bytes_mode: bool) -> Self {
28        Self {
29            _format: format,
30            _bytes_mode: bytes_mode,
31        }
32    }
33}
34
35impl OutputHandler for DefaultOutputHandler {
36    fn handle_result(&self, _result: &TestResult) -> Result<(), Error> {
37        // Default handler delegates to existing formatter logic
38        // This could be extended to use trait objects for different formats
39        Ok(())
40    }
41
42    fn handle_error(&self, error: &Error) -> Result<(), Error> {
43        eprintln!("Error: {}", error);
44        Ok(())
45    }
46}