Skip to main content

objectiveai_sdk/functions/
full_function.rs

1use serde::{Deserialize, Serialize};
2use schemars::JsonSchema;
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, arbitrary::Arbitrary)]
5#[serde(untagged)]
6#[schemars(rename = "functions.FullRemoteFunction")]
7pub enum FullRemoteFunction {
8    #[schemars(title = "Alpha")]
9    Alpha(AlphaRemoteFunction),
10    #[schemars(title = "Standard")]
11    Standard(super::RemoteFunction),
12}
13
14impl FullRemoteFunction {
15    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
16        enum Remotes<A, B> { A(A), B(B) }
17        impl<'a, A: Iterator<Item = &'a crate::RemotePath>, B: Iterator<Item = &'a crate::RemotePath>> Iterator for Remotes<A, B> {
18            type Item = &'a crate::RemotePath;
19            fn next(&mut self) -> Option<Self::Item> {
20                match self { Remotes::A(a) => a.next(), Remotes::B(b) => b.next() }
21            }
22        }
23        match self {
24            FullRemoteFunction::Alpha(f) => Remotes::A(f.remotes()),
25            FullRemoteFunction::Standard(f) => Remotes::B(f.remotes()),
26        }
27    }
28
29    pub fn transpile(self) -> super::RemoteFunction {
30        match self {
31            FullRemoteFunction::Alpha(function) => function.transpile(),
32            FullRemoteFunction::Standard(function) => function,
33        }
34    }
35}
36
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
38#[serde(untagged)]
39#[schemars(rename = "functions.FullInlineFunction")]
40pub enum FullInlineFunction {
41    #[schemars(title = "Alpha")]
42    Alpha(AlphaInlineFunction),
43    #[schemars(title = "Standard")]
44    Standard(super::InlineFunction),
45}
46
47impl FullInlineFunction {
48    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
49        enum Remotes<A, B> { A(A), B(B) }
50        impl<'a, A: Iterator<Item = &'a crate::RemotePath>, B: Iterator<Item = &'a crate::RemotePath>> Iterator for Remotes<A, B> {
51            type Item = &'a crate::RemotePath;
52            fn next(&mut self) -> Option<Self::Item> {
53                match self { Remotes::A(a) => a.next(), Remotes::B(b) => b.next() }
54            }
55        }
56        match self {
57            FullInlineFunction::Alpha(f) => Remotes::A(f.remotes()),
58            FullInlineFunction::Standard(f) => Remotes::B(f.remotes()),
59        }
60    }
61
62    pub fn transpile(self) -> super::InlineFunction {
63        match self {
64            FullInlineFunction::Alpha(function) => function.transpile(),
65            FullInlineFunction::Standard(function) => function,
66        }
67    }
68}
69
70#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, arbitrary::Arbitrary)]
71#[serde(untagged)]
72#[schemars(rename = "functions.AlphaRemoteFunction")]
73pub enum AlphaRemoteFunction {
74    #[schemars(title = "Scalar")]
75    Scalar(super::alpha_scalar::RemoteFunction),
76    #[schemars(title = "Vector")]
77    Vector(super::alpha_vector::RemoteFunction),
78}
79
80impl AlphaRemoteFunction {
81    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
82        enum Remotes<A, B> { A(A), B(B) }
83        impl<'a, A: Iterator<Item = &'a crate::RemotePath>, B: Iterator<Item = &'a crate::RemotePath>> Iterator for Remotes<A, B> {
84            type Item = &'a crate::RemotePath;
85            fn next(&mut self) -> Option<Self::Item> {
86                match self { Remotes::A(a) => a.next(), Remotes::B(b) => b.next() }
87            }
88        }
89        match self {
90            AlphaRemoteFunction::Scalar(f) => Remotes::A(f.remotes()),
91            AlphaRemoteFunction::Vector(f) => Remotes::B(f.remotes()),
92        }
93    }
94
95    pub fn transpile(self) -> super::RemoteFunction {
96        match self {
97            AlphaRemoteFunction::Scalar(function) => function.transpile(),
98            AlphaRemoteFunction::Vector(function) => function.transpile(),
99        }
100    }
101}
102
103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
104#[serde(untagged)]
105#[schemars(rename = "functions.AlphaInlineFunction")]
106pub enum AlphaInlineFunction {
107    #[schemars(title = "Scalar")]
108    Scalar(super::alpha_scalar::InlineFunction),
109    #[schemars(title = "Vector")]
110    Vector(super::alpha_vector::InlineFunction),
111}
112
113impl AlphaInlineFunction {
114    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
115        enum Remotes<A, B> { A(A), B(B) }
116        impl<'a, A: Iterator<Item = &'a crate::RemotePath>, B: Iterator<Item = &'a crate::RemotePath>> Iterator for Remotes<A, B> {
117            type Item = &'a crate::RemotePath;
118            fn next(&mut self) -> Option<Self::Item> {
119                match self { Remotes::A(a) => a.next(), Remotes::B(b) => b.next() }
120            }
121        }
122        match self {
123            AlphaInlineFunction::Scalar(f) => Remotes::A(f.remotes()),
124            AlphaInlineFunction::Vector(f) => Remotes::B(f.remotes()),
125        }
126    }
127
128    pub fn transpile(self) -> super::InlineFunction {
129        match self {
130            AlphaInlineFunction::Scalar(function) => function.transpile(),
131            AlphaInlineFunction::Vector(function) => function.transpile(),
132        }
133    }
134}
135
136/// A full function, either remote or inline.
137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
138#[serde(untagged)]
139#[schemars(rename = "functions.FullFunction")]
140pub enum FullFunction {
141    #[schemars(title = "Remote")]
142    Remote(FullRemoteFunction),
143    #[schemars(title = "Inline")]
144    Inline(FullInlineFunction),
145}
146
147impl FullFunction {
148    pub fn remotes(&self) -> impl Iterator<Item = &crate::RemotePath> {
149        enum Remotes<A, B> { A(A), B(B) }
150        impl<'a, A: Iterator<Item = &'a crate::RemotePath>, B: Iterator<Item = &'a crate::RemotePath>> Iterator for Remotes<A, B> {
151            type Item = &'a crate::RemotePath;
152            fn next(&mut self) -> Option<Self::Item> {
153                match self { Remotes::A(a) => a.next(), Remotes::B(b) => b.next() }
154            }
155        }
156        match self {
157            FullFunction::Remote(f) => Remotes::A(f.remotes()),
158            FullFunction::Inline(f) => Remotes::B(f.remotes()),
159        }
160    }
161}
162
163/// A function specification that is either a full inline function definition
164/// or a remote path reference.
165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
166#[serde(untagged)]
167#[schemars(rename = "functions.FullInlineFunctionOrRemoteCommitOptional")]
168pub enum FullInlineFunctionOrRemoteCommitOptional {
169    #[schemars(title = "Inline")]
170    Inline(FullInlineFunction),
171    #[schemars(title = "Remote")]
172    Remote(crate::RemotePathCommitOptional),
173}