1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/// Rust source code defining the UDF entrypoint and any helper functions.
#[derive(
Debug,
Clone,
conjure_object::serde::Serialize,
conjure_object::serde::Deserialize,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash
)]
#[serde(crate = "conjure_object::serde")]
#[conjure_object::private::staged_builder::staged_builder]
#[builder(crate = conjure_object::private::staged_builder, update, inline)]
pub struct RustUdfSource {
#[builder(into)]
#[serde(rename = "sourceCode")]
source_code: String,
}
impl RustUdfSource {
/// Constructs a new instance of the type.
#[inline]
pub fn new(source_code: impl Into<String>) -> Self {
Self::builder().source_code(source_code).build()
}
/// Rust source code to transpiled into WASM. The source may contain a single function as the entrypoint, or if several
/// functions appear at the top level, annotate the entrypoint with `#[main]`. Entrypoint must return a scalar value
/// matching the containing series type.
/// Parameters must be typed as `f64` for numeric inputs or `String` for categorical inputs.
///
/// Single function example:
/// ```ignore
/// fn run(a: f64, b: f64) -> f64 {
/// a + b
/// }
///
/// ```
///
/// Main with helper function:
/// ```ignore
/// #[main]
/// fn run(sample: f64, band_size: f64) -> f64 {
/// excedance_count(sample, band_size)
/// }
///
/// fn excedance_count(value: f64, band_size: f64) -> f64 {
/// let mut excedances = 0.0;
/// for i in 1..=5 {
/// if value > band_size * i as f64 {
/// excedances += 1.0;
/// }
/// }
/// excedances
/// }
/// ```
#[inline]
pub fn source_code(&self) -> &str {
&*self.source_code
}
}