Closed as not planned
Closed as not planned
Description
impl_helper_methods
worked reasonably well while prototyping, but now I realized a trait with default provided methods is a better fit for making it easier and less verbose to implement command wrappers. This is because command_output
can be a required method checked by rustc, while we can provide helper methods but still allow individual command wrapper instances to override as desired.
pub trait CommandWrapper {
// required method
fn command_output(self) -> std::command::Output;
// provided helper methods
fn run(self) -> std::command::Output { ... }
fn run_fail(self, expected_exit_code: i32) -> std::command::Output { ... }
}
then implementors can write
pub struct Rustc { cmd: Command }
impl CommandWrapper for Rustc {
fn command_output(self) -> Output { ... }
}
impl Rustc {
// ... other helper methods
}
Unresolved questions
- If these helper methods are moved on to a trait, then test writers will have to bring the trait in scope in order to use the helper methods. Is it worth the extra typing?