Skip to content

Commit

Permalink
more direct ToString impls :(
Browse files Browse the repository at this point in the history
  • Loading branch information
EclecticGriffin committed Dec 10, 2024
1 parent de6c9eb commit 726c704
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 11 additions & 8 deletions calyx-utils/src/out_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
fmt::Display,
io::{self, BufWriter},
path::PathBuf,
str::FromStr,
Expand Down Expand Up @@ -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 => "<err>".to_string(),
OutputFile::Null => "<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 => "<err>",
OutputFile::Null => "<null>",
OutputFile::File { path, .. } => path.to_str().unwrap(),
};

string.fmt(f)
}
}

Expand Down
8 changes: 4 additions & 4 deletions calyx-utils/src/pos_string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{fmt::Display, path::PathBuf};

use crate::{GPosIdx, WithPos};

Expand Down Expand Up @@ -30,9 +30,9 @@ impl From<PosString> 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)
}
}

Expand Down

0 comments on commit 726c704

Please sign in to comment.