roopes_core/aggregates/executable_command/
mod.rs

1//!
2#![cfg_attr(feature = "doc-images",
3  cfg_attr(
4    all(),
5    doc = ::embed_doc_image::embed_image!(
6        "executable-command-diagram",
7        "src/aggregates/executable_command/executable_command.svg"
8)))]
9#![cfg_attr(
10    not(feature = "doc-images"),
11    doc = "**Doc images not enabled**. Compile with feature `doc-images` and \
12           Rust version >= 1.54 to enable."
13)]
14//!  The [`executable_command`] module creates
15//! [`Executable`]s from arbitrary [`Command`]s.
16//! ![executable command diagram][executable-command-diagram]
17
18use crate::prelude::*;
19use delegate::delegate;
20
21/// Exposes the default public types for the
22/// [`executable_command`] module.
23pub mod prelude
24{
25    pub use super::ExecutableCommand;
26}
27
28/// Bridges [`Command`]s and [`Executable`]s into
29/// one type, which implements both traits.
30pub struct ExecutableCommand<C>
31where
32    C: Command,
33{
34    command: C,
35}
36
37impl<C> ExecutableCommand<C>
38where
39    C: Command,
40{
41    /// Creates a new [`ExecutableCommand`] from
42    /// the specified [`Command`].
43    pub fn new(command: C) -> ExecutableCommand<C>
44    {
45        ExecutableCommand { command }
46    }
47}
48
49#[allow(clippy::inline_always)]
50impl<C> Executable for ExecutableCommand<C>
51where
52    C: Command,
53{
54    delegate! {
55        to self.command {
56           fn execute(&self);
57       }
58    }
59}
60
61#[allow(clippy::inline_always)]
62impl<C> Command for ExecutableCommand<C>
63where
64    C: Command,
65{
66    delegate! {
67             to self.command {
68            fn execute(&self);
69        }
70    }
71}
72
73impl<C> From<C> for ExecutableCommand<C>
74where
75    C: Command,
76{
77    fn from(command: C) -> Self
78    {
79        ExecutableCommand::new(command)
80    }
81}