Skip to main content

objectiveai_sdk/functions/
full_function.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(
5    Debug,
6    Clone,
7    PartialEq,
8    Serialize,
9    Deserialize,
10    JsonSchema,
11    arbitrary::Arbitrary,
12)]
13#[serde(untagged)]
14#[schemars(rename = "functions.FullRemoteFunction")]
15pub enum FullRemoteFunction {
16    #[schemars(title = "Alpha")]
17    Alpha(AlphaRemoteFunction),
18    #[schemars(title = "Standard")]
19    Standard(super::RemoteFunction),
20}
21
22impl FullRemoteFunction {
23    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
24        enum Remotes<A, B> {
25            A(A),
26            B(B),
27        }
28        impl<
29            'a,
30            A: Iterator<Item = &'a crate::RemotePath>,
31            B: Iterator<Item = &'a crate::RemotePath>,
32        > Iterator for Remotes<A, B>
33        {
34            type Item = &'a crate::RemotePath;
35            fn next(&mut self) -> Option<Self::Item> {
36                match self {
37                    Remotes::A(a) => a.next(),
38                    Remotes::B(b) => b.next(),
39                }
40            }
41        }
42        match self {
43            FullRemoteFunction::Alpha(f) => Remotes::A(f.remotes()),
44            FullRemoteFunction::Standard(f) => Remotes::B(f.remotes()),
45        }
46    }
47
48    pub fn transpile(self) -> super::RemoteFunction {
49        match self {
50            FullRemoteFunction::Alpha(function) => function.transpile(),
51            FullRemoteFunction::Standard(function) => function,
52        }
53    }
54}
55
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
57#[serde(untagged)]
58#[schemars(rename = "functions.FullInlineFunction")]
59pub enum FullInlineFunction {
60    #[schemars(title = "Alpha")]
61    Alpha(AlphaInlineFunction),
62    #[schemars(title = "Standard")]
63    Standard(super::InlineFunction),
64}
65
66impl FullInlineFunction {
67    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
68        enum Remotes<A, B> {
69            A(A),
70            B(B),
71        }
72        impl<
73            'a,
74            A: Iterator<Item = &'a crate::RemotePath>,
75            B: Iterator<Item = &'a crate::RemotePath>,
76        > Iterator for Remotes<A, B>
77        {
78            type Item = &'a crate::RemotePath;
79            fn next(&mut self) -> Option<Self::Item> {
80                match self {
81                    Remotes::A(a) => a.next(),
82                    Remotes::B(b) => b.next(),
83                }
84            }
85        }
86        match self {
87            FullInlineFunction::Alpha(f) => Remotes::A(f.remotes()),
88            FullInlineFunction::Standard(f) => Remotes::B(f.remotes()),
89        }
90    }
91
92    pub fn transpile(self) -> super::InlineFunction {
93        match self {
94            FullInlineFunction::Alpha(function) => function.transpile(),
95            FullInlineFunction::Standard(function) => function,
96        }
97    }
98}
99
100#[derive(
101    Debug,
102    Clone,
103    PartialEq,
104    Serialize,
105    Deserialize,
106    JsonSchema,
107    arbitrary::Arbitrary,
108)]
109#[serde(untagged)]
110#[schemars(rename = "functions.AlphaRemoteFunction")]
111pub enum AlphaRemoteFunction {
112    #[schemars(title = "Scalar")]
113    Scalar(super::alpha_scalar::RemoteFunction),
114    #[schemars(title = "Vector")]
115    Vector(super::alpha_vector::RemoteFunction),
116}
117
118impl AlphaRemoteFunction {
119    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
120        enum Remotes<A, B> {
121            A(A),
122            B(B),
123        }
124        impl<
125            'a,
126            A: Iterator<Item = &'a crate::RemotePath>,
127            B: Iterator<Item = &'a crate::RemotePath>,
128        > Iterator for Remotes<A, B>
129        {
130            type Item = &'a crate::RemotePath;
131            fn next(&mut self) -> Option<Self::Item> {
132                match self {
133                    Remotes::A(a) => a.next(),
134                    Remotes::B(b) => b.next(),
135                }
136            }
137        }
138        match self {
139            AlphaRemoteFunction::Scalar(f) => Remotes::A(f.remotes()),
140            AlphaRemoteFunction::Vector(f) => Remotes::B(f.remotes()),
141        }
142    }
143
144    pub fn transpile(self) -> super::RemoteFunction {
145        match self {
146            AlphaRemoteFunction::Scalar(function) => function.transpile(),
147            AlphaRemoteFunction::Vector(function) => function.transpile(),
148        }
149    }
150}
151
152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
153#[serde(untagged)]
154#[schemars(rename = "functions.AlphaInlineFunction")]
155pub enum AlphaInlineFunction {
156    #[schemars(title = "Scalar")]
157    Scalar(super::alpha_scalar::InlineFunction),
158    #[schemars(title = "Vector")]
159    Vector(super::alpha_vector::InlineFunction),
160}
161
162impl AlphaInlineFunction {
163    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
164        enum Remotes<A, B> {
165            A(A),
166            B(B),
167        }
168        impl<
169            'a,
170            A: Iterator<Item = &'a crate::RemotePath>,
171            B: Iterator<Item = &'a crate::RemotePath>,
172        > Iterator for Remotes<A, B>
173        {
174            type Item = &'a crate::RemotePath;
175            fn next(&mut self) -> Option<Self::Item> {
176                match self {
177                    Remotes::A(a) => a.next(),
178                    Remotes::B(b) => b.next(),
179                }
180            }
181        }
182        match self {
183            AlphaInlineFunction::Scalar(f) => Remotes::A(f.remotes()),
184            AlphaInlineFunction::Vector(f) => Remotes::B(f.remotes()),
185        }
186    }
187
188    pub fn transpile(self) -> super::InlineFunction {
189        match self {
190            AlphaInlineFunction::Scalar(function) => function.transpile(),
191            AlphaInlineFunction::Vector(function) => function.transpile(),
192        }
193    }
194}
195
196/// A full function, either remote or inline.
197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
198#[serde(untagged)]
199#[schemars(rename = "functions.FullFunction")]
200pub enum FullFunction {
201    #[schemars(title = "Remote")]
202    Remote(FullRemoteFunction),
203    #[schemars(title = "Inline")]
204    Inline(FullInlineFunction),
205}
206
207impl FullFunction {
208    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
209        enum Remotes<A, B> {
210            A(A),
211            B(B),
212        }
213        impl<
214            'a,
215            A: Iterator<Item = &'a crate::RemotePath>,
216            B: Iterator<Item = &'a crate::RemotePath>,
217        > Iterator for Remotes<A, B>
218        {
219            type Item = &'a crate::RemotePath;
220            fn next(&mut self) -> Option<Self::Item> {
221                match self {
222                    Remotes::A(a) => a.next(),
223                    Remotes::B(b) => b.next(),
224                }
225            }
226        }
227        match self {
228            FullFunction::Remote(f) => Remotes::A(f.remotes()),
229            FullFunction::Inline(f) => Remotes::B(f.remotes()),
230        }
231    }
232}
233
234/// A function specification that is either a full inline function definition
235/// or a remote path reference.
236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
237#[serde(untagged)]
238#[schemars(rename = "functions.FullInlineFunctionOrRemoteCommitOptional")]
239pub enum FullInlineFunctionOrRemoteCommitOptional {
240    #[schemars(title = "Inline")]
241    Inline(FullInlineFunction),
242    #[schemars(title = "Remote")]
243    Remote(crate::RemotePathCommitOptional),
244}