Skip to content

Commit 37d6a83

Browse files
committed
Use From impls instead of factory functions
1 parent 3469682 commit 37d6a83

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

tests/difftests/bin/src/differ.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,26 @@ impl DifferenceDisplay for F32Differ {
246246
}
247247
}
248248

249-
/// Factory function to create appropriate differ based on output type
250-
pub fn create_differ(output_type: OutputType) -> Box<dyn OutputDiffer + Send + Sync> {
251-
match output_type {
252-
OutputType::Raw => Box::new(RawDiffer),
253-
OutputType::F32 => Box::new(F32Differ),
254-
OutputType::F64 => todo!("F64Differ not implemented yet"),
255-
OutputType::U32 => todo!("U32Differ not implemented yet"),
256-
OutputType::I32 => todo!("I32Differ not implemented yet"),
249+
impl From<OutputType> for Box<dyn OutputDiffer + Send + Sync> {
250+
fn from(output_type: OutputType) -> Self {
251+
match output_type {
252+
OutputType::Raw => Box::new(RawDiffer),
253+
OutputType::F32 => Box::new(F32Differ),
254+
OutputType::F64 => todo!("F64Differ not implemented yet"),
255+
OutputType::U32 => todo!("U32Differ not implemented yet"),
256+
OutputType::I32 => todo!("I32Differ not implemented yet"),
257+
}
257258
}
258259
}
259260

260-
/// Factory function to create appropriate display based on output type
261-
pub fn create_display(output_type: OutputType) -> Box<dyn DifferenceDisplay + Send + Sync> {
262-
match output_type {
263-
OutputType::Raw => Box::new(RawDiffer),
264-
OutputType::F32 => Box::new(F32Differ),
265-
OutputType::F64 => todo!("F64Display not implemented yet"),
266-
OutputType::U32 => todo!("U32Display not implemented yet"),
267-
OutputType::I32 => todo!("I32Display not implemented yet"),
261+
impl From<OutputType> for Box<dyn DifferenceDisplay + Send + Sync> {
262+
fn from(output_type: OutputType) -> Self {
263+
match output_type {
264+
OutputType::Raw => Box::new(RawDiffer),
265+
OutputType::F32 => Box::new(F32Differ),
266+
OutputType::F64 => todo!("F64Display not implemented yet"),
267+
OutputType::U32 => todo!("U32Display not implemented yet"),
268+
OutputType::I32 => todo!("I32Display not implemented yet"),
269+
}
268270
}
269271
}

tests/difftests/bin/src/runner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tempfile::NamedTempFile;
1212
use thiserror::Error;
1313
use tracing::{debug, error, info, trace};
1414

15-
use crate::differ::{Difference, DifferenceDisplay, OutputDiffer, create_differ, create_display};
15+
use crate::differ::{Difference, DifferenceDisplay, OutputDiffer};
1616

1717
#[derive(Debug, Error)]
1818
pub enum RunnerError {
@@ -386,8 +386,8 @@ impl Runner {
386386
let output_type = output_type.unwrap_or(OutputType::Raw);
387387
let groups = self.group_outputs(&pkg_outputs, epsilon, output_type);
388388
if groups.len() > 1 {
389-
let differ = create_differ(output_type);
390-
let display = create_display(output_type);
389+
let differ: Box<dyn OutputDiffer + Send + Sync> = output_type.into();
390+
let display: Box<dyn DifferenceDisplay + Send + Sync> = output_type.into();
391391

392392
// Write human-readable outputs
393393
for po in &pkg_outputs {

0 commit comments

Comments
 (0)