1use crate::blocks::CustomStage;
19use crate::escape::Emit;
20use crate::stage::FlowStage;
21use crate::value::FlowValue;
22
23pub struct PluginStage(CustomStage);
25
26impl PluginStage {
27 pub fn new<F>(f: F) -> Self
28 where
29 F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
30 + Send
31 + Sync
32 + 'static,
33 {
34 Self(CustomStage::new(f))
35 }
36
37 pub fn named<F>(name: impl Into<String>, f: F) -> Self
38 where
39 F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
40 + Send
41 + Sync
42 + 'static,
43 {
44 Self(CustomStage::named(name, f))
45 }
46
47 pub(crate) fn into_stage(self) -> FlowStage {
48 FlowStage::Custom(self.0)
49 }
50}
51
52pub fn plugin<F>(f: F) -> FlowStage
53where
54 F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
55 + Send
56 + Sync
57 + 'static,
58{
59 PluginStage::new(f).into_stage()
60}
61
62pub fn plugin_named<F>(name: impl Into<String>, f: F) -> FlowStage
63where
64 F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
65 + Send
66 + Sync
67 + 'static,
68{
69 PluginStage::named(name, f).into_stage()
70}