Skip to content

Commit f668b2e

Browse files
runner: Remove const from the Runner trait
Makes it possible to have Box<dyn Runner>
1 parent 787993c commit f668b2e

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/runner/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct RunnerInfo {
1818
name: String,
1919
version: String,
2020
directory: PathBuf,
21+
executable: PathBuf,
2122
}
2223

2324
impl RunnerInfo {
@@ -66,9 +67,15 @@ impl RunnerInfo {
6667
Ok(RunnerInfo {
6768
name,
6869
directory: directory.to_path_buf(),
70+
executable: executable.to_path_buf(),
6971
version,
7072
})
7173
}
74+
75+
/// Get the full path to the executable for the runner
76+
pub fn executable_path(&self) -> PathBuf {
77+
self.directory.join(&self.executable)
78+
}
7279
}
7380

7481
impl RunnerInfo {
@@ -89,13 +96,12 @@ impl RunnerInfo {
8996
}
9097

9198
pub trait Runner {
92-
const EXECUTABLE: &'static str;
9399
/// Get the common runner information
94100
fn info(&self) -> &RunnerInfo;
95101

96102
/// Check if the runner executable is available and functional
97103
fn is_available(&self) -> bool {
98-
let executable_path = self.info().directory().join(Self::EXECUTABLE);
104+
let executable_path = self.info().executable_path();
99105
executable_path.exists() && executable_path.is_file()
100106
}
101107
}

src/runner/proton.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ impl TryFrom<&Path> for Proton {
1313
type Error = Box<dyn std::error::Error>;
1414

1515
fn try_from(path: &Path) -> Result<Self, Self::Error> {
16-
let executable = PathBuf::from(Self::EXECUTABLE);
16+
let executable = PathBuf::from("./proton");
1717
let info = RunnerInfo::try_from(path, &executable)?;
1818
Ok(Proton { info })
1919
}
2020
}
2121

2222
impl Runner for Proton {
23-
const EXECUTABLE: &'static str = "proton";
2423
fn info(&self) -> &RunnerInfo {
2524
&self.info
2625
}

src/runner/umu.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl TryFrom<&Path> for UMU {
1111
type Error = Box<dyn std::error::Error>;
1212

1313
fn try_from(path: &Path) -> Result<Self, Self::Error> {
14-
let executable = PathBuf::from(Self::EXECUTABLE);
14+
let executable = PathBuf::from("./umu-run");
1515
let mut info = RunnerInfo::try_from(path, &executable)?;
1616
let pretty_version = info
1717
.version
@@ -28,7 +28,6 @@ impl TryFrom<&Path> for UMU {
2828
}
2929

3030
impl Runner for UMU {
31-
const EXECUTABLE: &'static str = "umu-run";
3231
fn info(&self) -> &RunnerInfo {
3332
&self.info
3433
}

src/runner/wine.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ impl TryFrom<&Path> for Wine {
2121
type Error = Box<dyn std::error::Error>;
2222

2323
fn try_from(path: &Path) -> Result<Self, Self::Error> {
24-
let executable = PathBuf::from(Self::EXECUTABLE);
24+
let executable = PathBuf::from("./bin/wine");
2525
let info = RunnerInfo::try_from(path, &executable)?;
2626
Ok(Wine { info })
2727
}
2828
}
2929

3030
impl Runner for Wine {
31-
const EXECUTABLE: &'static str = "bin/wine";
3231
fn info(&self) -> &RunnerInfo {
3332
&self.info
3433
}

0 commit comments

Comments
 (0)