@@ -16,17 +16,39 @@ use std::{
16
16
process:: Command ,
17
17
} ;
18
18
19
- /// Common information about a runner
19
+ /// Contains metadata and paths for any runner implementation. This struct is used
20
+ /// internally by all runner types to store their basic information.
20
21
#[ derive( Debug ) ]
21
22
pub struct RunnerInfo {
23
+ /// Human-readable name of the runner, typically derived from the directory name
22
24
name : String ,
25
+ /// Version string obtained from the runner's `--version` output
23
26
version : String ,
27
+ /// Base directory where the runner is installed
24
28
directory : PathBuf ,
29
+ /// Relative path to the main executable within the directory
25
30
executable : PathBuf ,
26
31
}
27
32
28
33
impl RunnerInfo {
29
- // This fuction is only meant to be called by the runners themselves hence this is not public
34
+ /// Create a new RunnerInfo by validating the directory and executable
35
+ ///
36
+ /// This function is only meant to be called by the runners themselves, hence it's not public.
37
+ /// It performs validation to ensure the directory exists and contains the specified executable.
38
+ ///
39
+ /// # Arguments
40
+ ///
41
+ /// * `directory` - The base directory where the runner is installed
42
+ /// * `executable` - The relative path to the executable within the directory
43
+ ///
44
+ /// # Returns
45
+ ///
46
+ /// Returns a `RunnerInfo` instance if validation succeeds
47
+ ///
48
+ /// # Errors
49
+ ///
50
+ /// This function will return an error if the directory or executable path is invalid,
51
+ /// or if the executable cannot be executed to determine its version.
30
52
fn try_from ( directory : & Path , executable : & Path ) -> Result < Self , Error > {
31
53
if !directory. exists ( ) {
32
54
return Err ( std:: io:: Error :: new (
@@ -77,41 +99,110 @@ impl RunnerInfo {
77
99
}
78
100
79
101
/// Get the full path to the executable for the runner
102
+ ///
103
+ /// Combines the base directory with the relative executable path to provide
104
+ /// the complete path that can be used to execute the runner.
105
+ ///
106
+ /// # Returns
107
+ ///
108
+ /// A `PathBuf` containing the full path to the runner's executable
80
109
pub fn executable_path ( & self ) -> PathBuf {
81
110
self . directory . join ( & self . executable )
82
111
}
83
112
}
84
113
85
114
impl RunnerInfo {
86
- /// Name of the runner
115
+ /// Get the name of the runner
116
+ ///
117
+ /// Returns the human-readable name, typically derived from the directory name
118
+ /// where the runner is installed.
119
+ ///
120
+ /// # Returns
121
+ ///
122
+ /// A string slice containing the runner's name
87
123
pub fn name ( & self ) -> & str {
88
124
& self . name
89
125
}
90
126
91
- /// Version of the runner
127
+ /// Get the version of the runner
128
+ ///
129
+ /// Returns the version string as reported by the runner's `--version` command.
130
+ /// If the version cannot be determined, this may return the runner's name instead.
131
+ ///
132
+ /// # Returns
133
+ ///
134
+ /// A string slice containing the runner's version information
92
135
pub fn version ( & self ) -> & str {
93
136
& self . version
94
137
}
95
138
96
- /// Directory where the runner is located
139
+ /// Returns the directory path where the runner is installed.
140
+ ///
141
+ /// # Returns
142
+ ///
143
+ /// A path reference to the runner's installation directory
97
144
pub fn directory ( & self ) -> & Path {
98
145
& self . directory
99
146
}
100
147
}
101
148
149
+ /// Trait defining the common interface for all Windows compatibility runners
150
+ ///
151
+ /// All runners in this module implement this trait, providing a unified way to interact
152
+ /// with different compatibility layers like Wine, Proton, UMU, and GPTK.
102
153
pub trait Runner {
103
154
/// Get the Wine runner associated with this runner
104
155
///
105
- /// This is possible because all runners are built on top of Wine
156
+ /// All runners are built on top of Wine, so this method provides access to the
157
+ /// underlying Wine instance. This allows for Wine-specific operations and
158
+ /// configuration even when using higher-level runners like Proton.
159
+ ///
160
+ /// # Returns
161
+ ///
162
+ /// A reference to the underlying Wine runner instance
106
163
fn wine ( & self ) -> & Wine ;
107
164
108
- /// Get the common runner information
165
+ /// Provides access to metadata about the runner including its name, version,
166
+ /// installation directory, and executable path.
167
+ ///
168
+ /// # Returns
169
+ ///
170
+ /// A reference to the runner's information structure
109
171
fn info ( & self ) -> & RunnerInfo ;
110
172
111
- /// Get the common runner information
173
+ /// Get a mutable reference to the common runner information
174
+ ///
175
+ /// Allows modification of the runner's metadata. This is typically used
176
+ /// internally by runner implementations during initialization.
177
+ ///
178
+ /// # Returns
179
+ ///
180
+ /// A mutable reference to the runner's information structure
112
181
fn info_mut ( & mut self ) -> & mut RunnerInfo ;
113
182
114
- /// Check if the runner executable is available and functional
183
+ /// Performs basic validation to ensure the runner can be executed. The default
184
+ /// implementation checks if the executable file exists and is accessible.
185
+ /// Individual runners may override this to perform additional checks.
186
+ ///
187
+ /// # Returns
188
+ ///
189
+ /// `true` if the runner appears to be functional, `false` otherwise
190
+ ///
191
+ /// # Example
192
+ ///
193
+ /// ```rust
194
+ /// use bottles_core::runner::{Wine, Runner};
195
+ /// use std::path::Path;
196
+ ///
197
+ /// let wine_path = Path::new("/usr/bin/wine");
198
+ /// if let Ok(wine) = Wine::try_from(wine_path) {
199
+ /// if wine.is_available() {
200
+ /// println!("Wine is ready to use");
201
+ /// } else {
202
+ /// println!("Wine is not available");
203
+ /// }
204
+ /// }
205
+ /// ```
115
206
fn is_available ( & self ) -> bool {
116
207
let executable_path = self . info ( ) . executable_path ( ) ;
117
208
executable_path. exists ( ) && executable_path. is_file ( )
0 commit comments