Command trait ref (#364)

This commit is contained in:
Nathan West 2020-01-14 11:47:32 -05:00 committed by Timon
parent 9da9c1f5ad
commit 938ec95b40
2 changed files with 27 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# master
- Added a generic implementation `Command` for `&T: Command`. This allows
commands to be queued by reference, as well as by value.
# Version 0.14.2 # Version 0.14.2
- Fix TIOCGWINSZ for FreeBSD - Fix TIOCGWINSZ for FreeBSD

View File

@ -39,6 +39,27 @@ pub trait Command {
} }
} }
impl<T: Command> Command for &T {
type AnsiType = T::AnsiType;
#[inline]
fn ansi_code(&self) -> Self::AnsiType {
T::ansi_code(self)
}
#[inline]
#[cfg(windows)]
fn execute_winapi(&self) -> Result<()> {
T::execute_winapi(self)
}
#[cfg(windows)]
#[inline]
fn is_ansi_code_supported(&self) -> bool {
T::is_ansi_code_supported(self)
}
}
/// An interface for commands that can be queued for further execution. /// An interface for commands that can be queued for further execution.
pub trait QueueableCommand<T: Display>: Sized { pub trait QueueableCommand<T: Display>: Sized {
/// Queues the given command for further execution. /// Queues the given command for further execution.