Skip to content

Commit

Permalink
Merge pull request #1511 from GuillaumeGomez/cleanup-profile-conversions
Browse files Browse the repository at this point in the history
Clean up code conversions of Profile enum
  • Loading branch information
Kobzol authored Jan 19, 2023
2 parents 2f13590 + 24d06c9 commit 3af3ba1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
7 changes: 1 addition & 6 deletions database/src/bin/ingest-json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,7 @@ async fn ingest<T: Ingesting>(conn: &T, caches: &mut IdCache, path: &Path) {
} else {
Profile::Debug
};
let profile_str = match profile {
Profile::Check => "check",
Profile::Debug => "debug",
Profile::Doc => "doc",
Profile::Opt => "opt",
};
let profile_str = profile.as_str();
let state = match &run.state {
BenchmarkState::Clean => Scenario::Empty,
BenchmarkState::IncrementalStart => Scenario::IncrementalEmpty,
Expand Down
22 changes: 12 additions & 10 deletions database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ pub enum Profile {
Opt,
}

impl Profile {
pub fn as_str(self) -> &'static str {
match self {
Profile::Check => "check",
Profile::Opt => "opt",
Profile::Debug => "debug",
Profile::Doc => "doc",
}
}
}

impl std::str::FromStr for Profile {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand All @@ -241,16 +252,7 @@ impl std::str::FromStr for Profile {

impl fmt::Display for Profile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
Profile::Check => "check",
Profile::Opt => "opt",
Profile::Debug => "debug",
Profile::Doc => "doc",
}
)
write!(f, "{}", self.as_str())
}
}

Expand Down
8 changes: 1 addition & 7 deletions database/src/pool/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,7 @@ where
row.get::<_, i32>(0) as u32,
(
Benchmark::from(row.get::<_, String>(1).as_str()),
match row.get::<_, String>(2).as_str() {
"check" => Profile::Check,
"opt" => Profile::Opt,
"debug" => Profile::Debug,
"doc" => Profile::Doc,
o => unreachable!("{}: not a profile", o),
},
Profile::from_str(row.get::<_, String>(2).as_str()).unwrap(),
row.get::<_, String>(3).as_str().parse().unwrap(),
row.get::<_, String>(4).as_str().into(),
),
Expand Down
8 changes: 1 addition & 7 deletions database/src/pool/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,7 @@ impl Connection for SqliteConnection {
row.get::<_, i32>(0)? as u32,
(
Benchmark::from(row.get::<_, String>(1)?.as_str()),
match row.get::<_, String>(2)?.as_str() {
"check" => Profile::Check,
"opt" => Profile::Opt,
"debug" => Profile::Debug,
"doc" => Profile::Doc,
o => unreachable!("{}: not a profile", o),
},
Profile::from_str(row.get::<_, String>(2)?.as_str()).unwrap(),
row.get::<_, String>(3)?.as_str().parse().unwrap(),
row.get::<_, String>(4)?.as_str().into(),
),
Expand Down

0 comments on commit 3af3ba1

Please sign in to comment.