roopes_core/primitives/executable/
heap.rs

1//! Provides a heap-based [`Executable`] which
2//! redirects [`Executable::execute`] calls to a
3//! delegate [`Executable`].  Useful when
4//! redirecting calls to unknown or mixed lists of
5//! [`Executable`]s.
6
7use super::Executable;
8
9/// Stores an indirected [`Executable`] in a
10/// [`Box`] for later delegation.
11pub struct Heap
12{
13    delegate: Box<dyn super::Executable>,
14}
15
16impl Heap
17{
18    /// Creates a new [`Heap`] with a given
19    /// [`Box`]ed [`Executable`]. # Examples
20    /// ``` rust
21    /// use roopes::prelude::*;
22    /// let my_executable =
23    ///     executable::Heap::new(Box::new(executable::Lambda::new(|| {
24    ///         println!("Hello World.");
25    ///     })));
26    /// my_executable.execute();
27    /// ```
28    #[must_use]
29    pub fn new(delegate: Box<dyn super::Executable>) -> Self
30    {
31        Self { delegate }
32    }
33}
34
35impl Executable for Heap
36{
37    fn execute(&self)
38    {
39        self.delegate.execute();
40    }
41}