1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Defines the [`Decoration`] trait.

use crate::node::InvocationOf;
use crate::node::NodeImpl;

/// A decoration around a `Node`.
///
/// Use [`decorated_with`][decorated_with] to wrap a decoration around a node.
///
/// [decorated_with]: crate::node::builder::ExtensibleNodeBuilder::decorated_with
pub trait Decoration
where
    Self: NodeImpl,
{
    /// Arguments this decoration requires.
    ///
    /// See [`decorated_with`][decorated_with].
    ///
    /// [decorated_with]: crate::node::builder::ExtensibleNodeBuilder::decorated_with
    type Arguments: 'static;

    /// Type of the decorated node.
    type Decorated: NodeImpl<Invocation = InvocationOf<Self>>;

    /// Wraps this decoration around the given node, using the given arguments.
    fn wrap(
        decorated: Self::Decorated,
        arguments: Self::Arguments,
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync + 'static>>;

    /// Returns a reference to the decorated node.
    fn peek_into(decorated: &Self) -> &Self::Decorated;

    /// Unwraps this decoration.
    fn unwrap(decorated: Self) -> Self::Decorated;
}