dataflow_rs/function/
spec.rs1use crate::expr::FieldSpec;
4use std::borrow::Cow;
5
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum RetrySafety {
10 Idempotent,
12 NotIdempotent,
14 #[default]
16 Unknown,
17}
18
19#[derive(Clone, Debug, PartialEq, Eq)]
21#[non_exhaustive]
22pub struct Reference {
23 pub field: Cow<'static, str>,
25 pub kind: Cow<'static, str>,
27}
28
29impl Reference {
30 pub fn new(field: impl Into<Cow<'static, str>>, kind: impl Into<Cow<'static, str>>) -> Self {
32 Self {
33 field: field.into(),
34 kind: kind.into(),
35 }
36 }
37}
38
39#[derive(Clone, Debug, Default)]
41#[non_exhaustive]
42pub struct FunctionSpec {
43 pub description: Cow<'static, str>,
45 pub category: Cow<'static, str>,
47 pub retry: RetrySafety,
49 pub references: Vec<Reference>,
51 pub runtime_fields: Option<Vec<FieldSpec>>,
53}
54
55impl FunctionSpec {
56 #[must_use]
58 pub fn with_description(mut self, description: impl Into<Cow<'static, str>>) -> Self {
59 self.description = description.into();
60 self
61 }
62
63 #[must_use]
65 pub fn with_category(mut self, category: impl Into<Cow<'static, str>>) -> Self {
66 self.category = category.into();
67 self
68 }
69
70 #[must_use]
72 pub fn with_retry(mut self, retry: RetrySafety) -> Self {
73 self.retry = retry;
74 self
75 }
76
77 #[must_use]
79 pub fn with_references(mut self, references: Vec<Reference>) -> Self {
80 self.references = references;
81 self
82 }
83
84 #[must_use]
86 pub fn with_runtime_fields(mut self, fields: Vec<FieldSpec>) -> Self {
87 self.runtime_fields = Some(fields);
88 self
89 }
90}