dfir_lang/graph/ops/identity.rs
1use super::{
2 OperatorCategory, OperatorConstraints, IDENTITY_WRITE_FN, RANGE_0, RANGE_1,
3};
4
5/// > 1 input stream of type T, 1 output stream of type T
6///
7/// For each item passed in, pass it out without any change.
8///
9/// ```dfir
10/// source_iter(vec!["hello", "world"])
11/// -> identity()
12/// -> assert_eq(["hello", "world"]);
13/// ```
14///
15/// You can also supply a type parameter `identity::<MyType>()` to specify what items flow through the
16/// the pipeline. This can be useful for helping the compiler infer types.
17///
18/// ```dfir
19/// // Use type parameter to ensure items are `i32`s.
20/// source_iter(0..10)
21/// -> identity::<i32>()
22/// -> assert_eq([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
23/// ```
24pub const IDENTITY: OperatorConstraints = OperatorConstraints {
25 name: "identity",
26 categories: &[OperatorCategory::Map],
27 hard_range_inn: RANGE_1,
28 soft_range_inn: RANGE_1,
29 hard_range_out: RANGE_1,
30 soft_range_out: RANGE_1,
31 num_args: 0,
32 persistence_args: RANGE_0,
33 type_args: &(0..=1),
34 is_external_input: false,
35 has_singleton_output: false,
36 flo_type: None,
37 ports_inn: None,
38 ports_out: None,
39 input_delaytype_fn: |_| None,
40 write_fn: IDENTITY_WRITE_FN,
41};