Skip to content

Commit 24d06c9

Browse files
Clean up code conversions of Profile enum
1 parent fc632ec commit 24d06c9

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

database/src/bin/ingest-json.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,7 @@ async fn ingest<T: Ingesting>(conn: &T, caches: &mut IdCache, path: &Path) {
921921
} else {
922922
Profile::Debug
923923
};
924-
let profile_str = match profile {
925-
Profile::Check => "check",
926-
Profile::Debug => "debug",
927-
Profile::Doc => "doc",
928-
Profile::Opt => "opt",
929-
};
924+
let profile_str = profile.as_str();
930925
let state = match &run.state {
931926
BenchmarkState::Clean => Scenario::Empty,
932927
BenchmarkState::IncrementalStart => Scenario::IncrementalEmpty,

database/src/lib.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ pub enum Profile {
226226
Opt,
227227
}
228228

229+
impl Profile {
230+
pub fn as_str(self) -> &'static str {
231+
match self {
232+
Profile::Check => "check",
233+
Profile::Opt => "opt",
234+
Profile::Debug => "debug",
235+
Profile::Doc => "doc",
236+
}
237+
}
238+
}
239+
229240
impl std::str::FromStr for Profile {
230241
type Err = String;
231242
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -241,16 +252,7 @@ impl std::str::FromStr for Profile {
241252

242253
impl fmt::Display for Profile {
243254
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
244-
write!(
245-
f,
246-
"{}",
247-
match self {
248-
Profile::Check => "check",
249-
Profile::Opt => "opt",
250-
Profile::Debug => "debug",
251-
Profile::Doc => "doc",
252-
}
253-
)
255+
write!(f, "{}", self.as_str())
254256
}
255257
}
256258

database/src/pool/postgres.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,7 @@ where
546546
row.get::<_, i32>(0) as u32,
547547
(
548548
Benchmark::from(row.get::<_, String>(1).as_str()),
549-
match row.get::<_, String>(2).as_str() {
550-
"check" => Profile::Check,
551-
"opt" => Profile::Opt,
552-
"debug" => Profile::Debug,
553-
"doc" => Profile::Doc,
554-
o => unreachable!("{}: not a profile", o),
555-
},
549+
Profile::from_str(row.get::<_, String>(2).as_str()).unwrap(),
556550
row.get::<_, String>(3).as_str().parse().unwrap(),
557551
row.get::<_, String>(4).as_str().into(),
558552
),

database/src/pool/sqlite.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,7 @@ impl Connection for SqliteConnection {
468468
row.get::<_, i32>(0)? as u32,
469469
(
470470
Benchmark::from(row.get::<_, String>(1)?.as_str()),
471-
match row.get::<_, String>(2)?.as_str() {
472-
"check" => Profile::Check,
473-
"opt" => Profile::Opt,
474-
"debug" => Profile::Debug,
475-
"doc" => Profile::Doc,
476-
o => unreachable!("{}: not a profile", o),
477-
},
471+
Profile::from_str(row.get::<_, String>(2)?.as_str()).unwrap(),
478472
row.get::<_, String>(3)?.as_str().parse().unwrap(),
479473
row.get::<_, String>(4)?.as_str().into(),
480474
),

0 commit comments

Comments
 (0)