use quote::quote_spanned;
use super::{
OperatorCategory, OperatorConstraints, OperatorWriteOutput, WriteContextArgs,
RANGE_0, RANGE_1,
};
pub const FLATTEN: OperatorConstraints = OperatorConstraints {
name: "flatten",
categories: &[OperatorCategory::Flatten],
hard_range_inn: RANGE_1,
soft_range_inn: RANGE_1,
hard_range_out: RANGE_1,
soft_range_out: RANGE_1,
num_args: 0,
persistence_args: RANGE_0,
type_args: RANGE_0,
is_external_input: false,
has_singleton_output: false,
flo_type: None,
ports_inn: None,
ports_out: None,
input_delaytype_fn: |_| None,
write_fn: |&WriteContextArgs {
root,
op_span,
ident,
inputs,
outputs,
is_pull,
..
},
_| {
let write_iterator = if is_pull {
let input = &inputs[0];
quote_spanned! {op_span=>
let #ident = #input.flatten();
}
} else {
let output = &outputs[0];
quote_spanned! {op_span=>
let #ident = #root::pusherator::flatten::Flatten::new(#output);
}
};
Ok(OperatorWriteOutput {
write_iterator,
..Default::default()
})
},
};