beetry-plugin 0.2.0

Internal beetry crate. For the public API, check the beetry crate.
Documentation
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/// Creates an action plugin from Beetry's leaf-node DSL.
///
/// The generated plugin:
///
/// - defines a `NodeSpec`
/// - defines optional port metadata and parameter metadata
/// - defines a factory that reconstructs the action from reconstruction data
/// - registers itself automatically
///
///
/// Minimal action without params or channels:
/// ```rust, no_run
/// # use anyhow::Result;
/// # use beetry_core::{ActionBehavior, ActionTask};
/// # use beetry_plugin::action;
/// struct WaitForSignal;
///
/// impl ActionBehavior for WaitForSignal {
///     fn task(&mut self) -> Result<ActionTask> {
///         # todo!()
///     }
/// }
///
/// action! {
///     WaitForSignalPlugin: "Wait For Signal";
///     create: WaitForSignal;
/// }
/// ```
///
/// Action with parameters:
///
/// Parameters are provided via `params(binding): ParamsType` syntax
///
/// Prerequisites: `ParamsType` is expected to implement
/// [`crate::ProvideParamSpec`] and be deserializable
///
/// ```rust, no_run
/// # use anyhow::Result;
/// # use beetry_core::{ActionBehavior, ActionTask};
/// # use beetry_editor_types::spec::node::{
/// #     FieldDefinition, FieldMetadata, FieldTypeSpec, ParamsSpec,
/// # };
/// # use beetry_plugin::{ProvideParamSpec, action};
/// # use mitsein::iter1::IntoIterator1;
/// # use serde::Deserialize;
/// #[derive(Deserialize)]
/// struct RetryParams {
///     retries: u64,
/// }
///
/// impl ProvideParamSpec for RetryParams {
///     fn provide() -> ParamsSpec {
///         # [(
///         #     "retries".into(),
///         #     FieldDefinition {
///         #         type_spec: FieldTypeSpec::U64(FieldMetadata::default()),
///         #         description: Some("Maximum retry count".into()),
///         #     },
///         # )]
///         # .into_iter1()
///         # .collect1()
///     }
/// }
///
/// struct RetryAction {
///     params: RetryParams,
/// }
///
/// impl RetryAction {
///     fn new(params: RetryParams) -> Self {
///         # Self { params }
///     }
/// }
///
/// impl ActionBehavior for RetryAction {
///     fn task(&mut self) -> Result<ActionTask> {
///         # let _ = self.params.retries;
///         # todo!()
///     }
/// }
///
/// action! {
///     RetryActionPlugin: "Retry Action";
///     params(parameters): RetryParams;
///     create: RetryAction::new(parameters);
/// }
/// ```
///
/// Action with one receiver and one sender:
///
/// ```rust, no_run
/// # use anyhow::Result;
/// # use beetry_channel::{Receiver, Sender};
/// # use beetry_core::{ActionBehavior, ActionTask};
/// # use beetry_macros::Message;
/// # use beetry_message::Message;
/// # use beetry_message::type_hash::{self, TypeHash};
/// # use beetry_plugin::action;
/// #[derive(Debug, Clone, Copy, Default, TypeHash, Message)]
/// struct Pose;
///
/// struct RelayPose<R, S>
/// where
///     R: Receiver<Pose>,
///     S: Sender<Pose>,
/// {
///     input: R,
///     output: S,
/// }
///
/// impl<R, S> RelayPose<R, S>
/// where
///     R: Receiver<Pose>,
///     S: Sender<Pose>,
/// {
///     fn new(input: R, output: S) -> Self {
///         Self { input, output }
///     }
/// }
///
/// impl<R, S> ActionBehavior for RelayPose<R, S>
/// where
///     R: Receiver<Pose>,
///     S: Sender<Pose>,
/// {
///     fn task(&mut self) -> Result<ActionTask> {
///         # let _ = (&mut self.input, &mut self.output);
///         # todo!()
///     }
/// }
///
/// action! {
///     RelayPosePlugin: "Relay Pose";
///     receivers: [input: Pose => "Incoming pose"];
///     senders: [output: Pose => "Republished pose"];
///     create: RelayPose::new(input, output);
/// }
/// ```
/// The DSL supports both parameters and ports, so action nodes that depend on
/// channels and parameters can be defined by combining the examples above.
#[macro_export]
macro_rules! action {
    ($plugin_name:ident : $name:expr; $($tokens:tt)*) => {
        $crate::__leaf_plugin_parse! {
            ctx: {
                plugin_name: $plugin_name,
                node_name: $name,
                factory_type: $crate::node::ActionFactory,
                plugin_constructor: $crate::node::ActionPluginConstructor,
                reconstruction_data: $crate::__macro_support::ActionReconstructionData,
                behavior_box_type: $crate::__macro_support::BoxActionBehavior,
                node_kind: $crate::__macro_support::NodeKind::action(),
            },
            receivers: [],
            senders: [],
            params: none,
            params_binding: _parameters,
            tokens: $($tokens)*
        }
    };
}

/// Creates a condition plugin from Beetry's leaf-node DSL.
///
/// Use when the node evaluates to success or failure without
/// producing child nodes.
///
/// The DSL is the same as [`action!`]: `receivers`, `senders`, `params`, and
/// `create` work the same way, but the constructed behavior must implement
/// `ConditionBehavior` instead of `ActionBehavior`.
#[macro_export]
macro_rules! condition {
    ($plugin_name:ident : $name:expr; $($tokens:tt)*) => {
        $crate::__leaf_plugin_parse! {
            ctx: {
                plugin_name: $plugin_name,
                node_name: $name,
                factory_type: $crate::node::ConditionFactory,
                plugin_constructor: $crate::node::ConditionPluginConstructor,
                reconstruction_data: $crate::__macro_support::ConditionReconstructionData,
                behavior_box_type: $crate::__macro_support::BoxConditionBehavior,
                node_kind: $crate::__macro_support::NodeKind::condition(),
            },
            receivers: [],
            senders: [],
            params: none,
            params_binding: _parameters,
            tokens: $($tokens)*
        }
    };
}

/// Creates a decorator plugin for nodes that wrap a single child.
///
/// Minimal example with a bound child node:
/// ```rust, no_run
/// # use beetry_core::{Node, TickStatus};
/// # use beetry_core::BoxNode;
/// # use beetry_editor_types::spec::node::{NodeKind, NodeName, NodeSpec, NodeSpecKey};
/// # use beetry_plugin::{
/// #     Plugin,
/// #     decorator,
/// #     node::{DecoratorFactory, DecoratorPluginConstructor, DecoratorReconstructionData},
/// # };
/// struct Invert<N>
/// {
///     child: N,
/// }
///
/// impl<N> Invert<N>
/// where
///     N: Node,
/// {
///     fn new(child: N) -> Self {
///         Self { child }
///     }
/// }
///
/// impl<N> Node for Invert<N>
/// where
///     N: Node,
/// {
///     fn tick(&mut self) -> TickStatus {
///     #    match self.child.tick() {
///     #        TickStatus::Success => TickStatus::Failure,
///     #        TickStatus::Failure => TickStatus::Success,
///     #        TickStatus::Running => TickStatus::Running,
///     #    }
///     }
/// }
///
/// decorator!(
///     InvertPlugin: "Invert";
///     child(child),
///     create: Invert::new(child),
/// );
/// ```
///
/// Parameters can be attached the same way as in [`action!`].
#[macro_export]
macro_rules! decorator {
    ($plugin_name:ident : $name:expr; child($child_binding:ident),create: $create:expr,) => {
        $crate::__decorator_plugin_impl! {
            $plugin_name,
            $name,
            $child_binding,
            none,
            _parameters,
            $create
        }
    };
    (
        $plugin_name:ident :
        $name:expr; child($child_binding:ident),params($params_binding:ident):
        $params_ty:path,create:
        $create:expr,
    ) => {
        $crate::__decorator_plugin_impl! {
            $plugin_name,
            $name,
            $child_binding,
            (typed $params_ty),
            $params_binding,
            $create
        }
    };
}

/// Creates a control plugin for nodes that manage multiple children.
///
///
/// Minimal example with bound child nodes:
/// ```rust, no_run
/// # use beetry_core::{BoxNode, Node, NonEmptyNodes, TickStatus};
/// # use beetry_editor_types::spec::node::{NodeKind, NodeName, NodeSpec, NodeSpecKey};
/// # use beetry_plugin::{
/// #     Plugin,
/// #     control,
/// #     node::{ControlFactory, ControlPluginConstructor, ControlReconstructionData},
/// # };
/// struct Sequence {
///     children: NonEmptyNodes,
/// }
///
/// impl Sequence {
///     fn new(children: NonEmptyNodes) -> Self {
///         Self { children }
///     }
/// }
///
/// impl Node for Sequence {
///     fn tick(&mut self) -> TickStatus {
///     #    for child in &mut self.children {
///     #        match child.tick() {
///     #            TickStatus::Success => continue,
///     #            TickStatus::Failure => return TickStatus::Failure,
///     #            TickStatus::Running => return TickStatus::Running,
///     #        }
///     #    }
///     #
///     #    TickStatus::Success
///     }
/// }
///
/// control!(
///     SequencePlugin: "Sequence";
///     children(children),
///     create: Sequence::new(children),
/// );
/// ```
///
/// Parameters are attached the same way as in [`action!`].
#[macro_export]
macro_rules! control {
    ($plugin_name:ident : $name:expr; children($children_binding:ident),create: $create:expr,) => {
        $crate::__control_plugin_impl! {
            $plugin_name,
            $name,
            $children_binding,
            none,
             _parameters,
            $create
        }
    };
    (
        $plugin_name:ident :
        $name:expr; children($children_binding:ident),params($params_binding:ident):
        $params_ty:path,create:
        $create:expr,
    ) => {
        $crate::__control_plugin_impl! {
            $plugin_name,
            $name,
            $children_binding,
            (typed $params_ty),
            $params_binding,
            $create
        }
    };
}

/// TT-muncher: parses plugin DSL tokens into
/// receivers/senders/params/params_binding and a final `create` expression,
/// then forwards parsed fields to the impl macro.
#[doc(hidden)]
#[macro_export]
macro_rules! __leaf_plugin_parse {
    (
        ctx: $ctx:tt,
        receivers: [$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),* $(,)?],
        senders: [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),* $(,)?],
        params: $params:tt,
        params_binding: $params_binding:ident,
        tokens: receivers: [$($new_receiver_name:ident : $new_receiver_ty:ty => $new_receiver_desc:literal),* $(,)?]; $($rest:tt)*
    ) => {
        $crate::__leaf_plugin_parse! {
            ctx: $ctx,
            receivers: [$($new_receiver_name : $new_receiver_ty => $new_receiver_desc),*],
            senders: [$($sender_name : $sender_ty => $sender_desc),*],
            params: $params,
            params_binding: $params_binding,
            tokens: $($rest)*
        }
    };
    (
        ctx: $ctx:tt,
        receivers: [$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),* $(,)?],
        senders: [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),* $(,)?],
        params: $params:tt,
        params_binding: $params_binding:ident,
        tokens: senders: [$($new_sender_name:ident : $new_sender_ty:ty => $new_sender_desc:literal),* $(,)?]; $($rest:tt)*
    ) => {
        $crate::__leaf_plugin_parse! {
            ctx: $ctx,
            receivers: [$($receiver_name : $receiver_ty => $receiver_desc),*],
            senders: [$($new_sender_name : $new_sender_ty => $new_sender_desc),*],
            params: $params,
            params_binding: $params_binding,
            tokens: $($rest)*
        }
    };
    (
        ctx: $ctx:tt,
        receivers: [$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),* $(,)?],
        senders: [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),* $(,)?],
        params: $params:tt,
        params_binding: $params_binding:ident,
        tokens: params($new_params_binding:ident): $new_params_ty:path; $($rest:tt)*
    ) => {
        $crate::__leaf_plugin_parse! {
            ctx: $ctx,
            receivers: [$($receiver_name : $receiver_ty => $receiver_desc),*],
            senders: [$($sender_name : $sender_ty => $sender_desc),*],
            params: (typed $new_params_ty),
            params_binding: $new_params_binding,
            tokens: $($rest)*
        }
    };
    (
        ctx: $ctx:tt,
        receivers: [$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),* $(,)?],
        senders: [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),* $(,)?],
        params: $params:tt,
        params_binding: $params_binding:ident,
        tokens: create: $create:expr $(;)?
    ) => {
        $crate::__leaf_plugin_impl! {
            ctx: $ctx,
            receivers: [$($receiver_name : $receiver_ty => $receiver_desc),*],
            senders: [$($sender_name : $sender_ty => $sender_desc),*],
            params: $params,
            params_binding: $params_binding,
            create: $create
        }
    };
    (
        ctx: $ctx:tt,
        receivers: [$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),* $(,)?],
        senders: [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),* $(,)?],
        params: $params:tt,
        params_binding: $params_binding:ident,
        tokens: $($unexpected:tt)+
    ) => {
        compile_error!(
            "invalid plugin DSL. Expected fields separated by ';': \
             receivers: [...]; senders: [...]; params(<ident>): <type-path>; create: <expr>;"
        );
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __leaf_plugin_extract_receivers {
    ([], $data:ident) => {};
    ([$($port_name:ident : $port_ty:ty => $port_desc:literal),+], $data:ident) => {
        $(
            let $port_name = $data
                .context
                .take_receiver(&$crate::__macro_support::PortKey::new(stringify!($port_name)))?
                .into_receiver_of::<$port_ty>()
                .map_err(|_| {
                    $crate::__macro_support::anyhow::anyhow!(
                        concat!(
                            "failed to obtain typed receiver for port '",
                            stringify!($port_name),
                            "'"
                        )
                    )
                })?;
        )+
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __leaf_plugin_extract_senders {
    ([], $data:ident) => {};
    ([$($port_name:ident : $port_ty:ty => $port_desc:literal),+], $data:ident) => {
        $(
            let $port_name = $data
                .context
                .take_sender(&$crate::__macro_support::PortKey::new(stringify!($port_name)))?
                .into_sender_of::<$port_ty>()
                .map_err(|_| {
                    $crate::__macro_support::anyhow::anyhow!(
                        concat!(
                            "failed to obtain typed sender for port '",
                            stringify!($port_name),
                            "'"
                        )
                    )
                })?;
        )+
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __leaf_plugin_build_ports {
    ([], []) => {
        None
    };
    ([$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),+], []) => {
        Some(
            <$crate::__macro_support::PortsSpec as $crate::__macro_support::FromIterator1<
                $crate::__macro_support::NodePortSpec,
            >>::from_iter1([
                $(
                    $crate::__macro_support::NodePortSpec {
                        key: $crate::__macro_support::PortKey::new(stringify!($receiver_name)),
                        kind: $crate::__macro_support::NodePortKind::Receiver,
                        msg_spec: $crate::__macro_support::MessageSpec::new::<$receiver_ty>($receiver_desc),
                    }
                ),+
            ]),
        )
    };
    ([], [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),+]) => {
        Some(
            <$crate::__macro_support::PortsSpec as $crate::__macro_support::FromIterator1<
                $crate::__macro_support::NodePortSpec,
            >>::from_iter1([
                $(
                    $crate::__macro_support::NodePortSpec {
                        key: $crate::__macro_support::PortKey::new(stringify!($sender_name)),
                        kind: $crate::__macro_support::NodePortKind::Sender,
                        msg_spec: $crate::__macro_support::MessageSpec::new::<$sender_ty>($sender_desc),
                    }
                ),+
            ]),
        )
    };
    ([$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),+], [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),+]) => {
        Some(
            <$crate::__macro_support::PortsSpec as $crate::__macro_support::FromIterator1<
                $crate::__macro_support::NodePortSpec,
            >>::from_iter1([
                $(
                    $crate::__macro_support::NodePortSpec {
                        key: $crate::__macro_support::PortKey::new(stringify!($receiver_name)),
                        kind: $crate::__macro_support::NodePortKind::Receiver,
                        msg_spec: $crate::__macro_support::MessageSpec::new::<$receiver_ty>($receiver_desc),
                    }
                ),+,
                $(
                    $crate::__macro_support::NodePortSpec {
                        key: $crate::__macro_support::PortKey::new(stringify!($sender_name)),
                        kind: $crate::__macro_support::NodePortKind::Sender,
                        msg_spec: $crate::__macro_support::MessageSpec::new::<$sender_ty>($sender_desc),
                    }
                ),+
            ]),
        )
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __optional_params_spec {
    (none) => {
        None
    };
    ((typed $params_ty:path)) => {
        Some(<$params_ty as $crate::ProvideParamSpec>::provide())
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __deserialize_params {
    (none, $params_binding:ident, $parameters:expr) => {};
    ((typed $params_ty:path), $params_binding:ident, $parameters:expr) => {
        let $params_binding = $crate::ParamsDeserializer::deserialize::<$params_ty>($parameters)?;
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __leaf_plugin_impl {
    (
        ctx: {
            plugin_name: $plugin_name:ident,
            node_name: $name:expr,
            factory_type: $factory_type:ty,
            plugin_constructor: $plugin_constructor:ty,
            reconstruction_data: $reconstruction_data:ty,
            behavior_box_type: $behavior_box_type:ty,
            node_kind: $node_kind:expr,
        },
        receivers: [$($receiver_name:ident : $receiver_ty:ty => $receiver_desc:literal),* $(,)?],
        senders: [$($sender_name:ident : $sender_ty:ty => $sender_desc:literal),* $(,)?],
        params: $params:tt,
        params_binding: $params_binding:ident,
        create: $create:expr $(,)?
    ) => {
        pub struct $plugin_name {
            spec: $crate::__macro_support::NodeSpec,
            factory: $factory_type,
        }

        impl $crate::Plugin for $plugin_name {
            type Spec = $crate::__macro_support::NodeSpec;
            type Factory = $factory_type;

            fn new() -> Self
            where
                Self: Sized,
            {
                let factory_fn = |mut data: $reconstruction_data| {
                    $crate::__leaf_plugin_extract_receivers!([$($receiver_name : $receiver_ty => $receiver_desc),*], data);
                    $crate::__leaf_plugin_extract_senders!([$($sender_name : $sender_ty => $sender_desc),*], data);
                    $crate::__deserialize_params!($params, $params_binding, data.parameters);
                    Ok(Box::new($create) as $behavior_box_type)
                };

                let spec = $crate::__macro_support::NodeSpec::builder()
                    .key($crate::__macro_support::NodeSpecKey::new(
                        $crate::__macro_support::NodeName::new($name),
                        $node_kind,
                    ))
                    .maybe_ports($crate::__leaf_plugin_build_ports!(
                        [$($receiver_name : $receiver_ty => $receiver_desc),*],
                        [$($sender_name : $sender_ty => $sender_desc),*]
                    ))
                    .maybe_params($crate::__optional_params_spec!($params))
                    .build();

                Self {
                    spec,
                    factory: Self::Factory::new(Box::new(factory_fn)),
                }
            }

            fn spec(&self) -> &Self::Spec {
                &self.spec
            }

            fn factory(&self) -> &Self::Factory {
                &self.factory
            }

            fn into_parts(self: Box<Self>) -> (Self::Spec, Self::Factory) {
                (self.spec, self.factory)
            }
        }

        $crate::submit!(<$plugin_constructor>::new::<$plugin_name>());
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __control_plugin_impl {
    (
        $plugin_name:ident,
        $name:expr,
        $children_binding:ident,
        $params:tt,
        $params_binding:ident,
        $create:expr $(,)?
    ) => {
        struct $plugin_name {
            spec: NodeSpec,
            factory: ControlFactory,
        }

        impl Plugin for $plugin_name {
            type Spec = NodeSpec;
            type Factory = ControlFactory;

            fn new() -> Self
            where
                Self: Sized,
            {
                Self {
                    spec: NodeSpec::builder()
                        .key(NodeSpecKey::new(NodeName::new($name), NodeKind::Control))
                        .maybe_params($crate::__optional_params_spec!($params))
                        .build(),

                    factory: ControlFactory::new(Box::new(|data: ControlReconstructionData| {
                        $crate::__deserialize_params!($params, $params_binding, data.parameters);
                        let $children_binding = data.context.children;

                        Ok(Box::new($create) as BoxNode)
                    })),
                }
            }

            fn spec(&self) -> &Self::Spec {
                &self.spec
            }

            fn factory(&self) -> &Self::Factory {
                &self.factory
            }

            fn into_parts(self: Box<Self>) -> (Self::Spec, Self::Factory) {
                (self.spec, self.factory)
            }
        }

        $crate::submit!(ControlPluginConstructor::new::<$plugin_name>());
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __decorator_plugin_impl {
    (
        $plugin_name:ident,
        $name:expr,
        $child_binding:ident,
        $params:tt,
        $params_binding:ident,
        $create:expr $(,)?
    ) => {
        struct $plugin_name {
            spec: NodeSpec,
            factory: DecoratorFactory,
        }

        impl Plugin for $plugin_name {
            type Spec = NodeSpec;
            type Factory = DecoratorFactory;

            fn new() -> Self
            where
                Self: Sized,
            {
                Self {
                    spec: NodeSpec::builder()
                        .key(NodeSpecKey::new(NodeName::new($name), NodeKind::Decorator))
                        .maybe_params($crate::__optional_params_spec!($params))
                        .build(),

                    factory: DecoratorFactory::new(Box::new(
                        |data: DecoratorReconstructionData| {
                            $crate::__deserialize_params!(
                                $params,
                                $params_binding,
                                data.parameters
                            );
                            let $child_binding = data.context.child;

                            Ok(Box::new($create) as BoxNode)
                        },
                    )),
                }
            }

            fn spec(&self) -> &Self::Spec {
                &self.spec
            }

            fn factory(&self) -> &Self::Factory {
                &self.factory
            }

            fn into_parts(self: Box<Self>) -> (Self::Spec, Self::Factory) {
                (self.spec, self.factory)
            }
        }

        $crate::submit!(DecoratorPluginConstructor::new::<$plugin_name>());
    };
}