diff --git a/calyx-utils/src/out_file.rs b/calyx-utils/src/out_file.rs index 16ac5ff65..c3edac848 100644 --- a/calyx-utils/src/out_file.rs +++ b/calyx-utils/src/out_file.rs @@ -1,4 +1,5 @@ use std::{ + fmt::Display, io::{self, BufWriter}, path::PathBuf, str::FromStr, @@ -48,14 +49,16 @@ impl FromStr for OutputFile { } } -impl ToString for OutputFile { - fn to_string(&self) -> String { - match self { - OutputFile::Stdout => "-".to_string(), - OutputFile::Stderr => "".to_string(), - OutputFile::Null => "".to_string(), - OutputFile::File { path, .. } => path.to_str().unwrap().to_string(), - } +impl Display for OutputFile { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let string = match self { + OutputFile::Stdout => "-", + OutputFile::Stderr => "", + OutputFile::Null => "", + OutputFile::File { path, .. } => path.to_str().unwrap(), + }; + + string.fmt(f) } } diff --git a/calyx-utils/src/pos_string.rs b/calyx-utils/src/pos_string.rs index 90c0b9691..d5cc617da 100644 --- a/calyx-utils/src/pos_string.rs +++ b/calyx-utils/src/pos_string.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{fmt::Display, path::PathBuf}; use crate::{GPosIdx, WithPos}; @@ -30,9 +30,9 @@ impl From for PathBuf { } } -impl ToString for PosString { - fn to_string(&self) -> String { - self.data.to_string() +impl Display for PosString { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.data.fmt(f) } }