use crate::blocks::CustomStage;
use crate::escape::Emit;
use crate::stage::FlowStage;
use crate::value::FlowValue;
pub struct PluginStage(CustomStage);
impl PluginStage {
pub fn new<F>(f: F) -> Self
where
F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
+ Send
+ Sync
+ 'static,
{
Self(CustomStage::new(f))
}
pub fn named<F>(name: impl Into<String>, f: F) -> Self
where
F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
+ Send
+ Sync
+ 'static,
{
Self(CustomStage::named(name, f))
}
pub(crate) fn into_stage(self) -> FlowStage {
FlowStage::Custom(self.0)
}
}
pub fn plugin<F>(f: F) -> FlowStage
where
F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
+ Send
+ Sync
+ 'static,
{
PluginStage::new(f).into_stage()
}
pub fn plugin_named<F>(name: impl Into<String>, f: F) -> FlowStage
where
F: Fn(&mut Emit<'_>, Option<FlowValue>) -> anyhow::Result<Option<FlowValue>>
+ Send
+ Sync
+ 'static,
{
PluginStage::named(name, f).into_stage()
}