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
impl_helper_methodsworked 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 becausecommand_outputcan be a required method checked by rustc, while we can provide helper methods but still allow individual command wrapper instances to override as desired.then implementors can write
Unresolved questions