rust_tvtf_api/
arg.rs

1use serde::{Deserialize, Serialize};
2
3pub type Args = Vec<Arg>;
4
5#[derive(Debug, Clone, Deserialize)]
6#[serde(tag = "type", content = "value")]
7#[serde(rename_all = "lowercase")]
8pub enum Arg {
9    Int(i64),
10    String(String),
11    Bool(bool),
12    Float(f64),
13    Timestamp(i64),
14    Interval(String),
15    Column(String),
16}
17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
19#[serde(rename_all = "UPPERCASE")]
20pub enum ArgType {
21    Int,
22    String,
23    Bool,
24    Float,
25    Timestamp,
26    Interval,
27    Column,
28}
29
30impl Arg {
31    pub fn is_scalar(&self) -> bool {
32        use Arg as T;
33        matches!(
34            self,
35            T::Int(_) | T::String(_) | T::Bool(_) | T::Float(_) | T::Timestamp(_) | T::Interval(_)
36        )
37    }
38
39    pub fn is_column(&self) -> bool {
40        use Arg as T;
41        matches!(self, T::Column(_))
42    }
43}
44
45#[cfg(test)]
46mod tests {
47
48    use anyhow::Context;
49    use serde_json::json;
50
51    use super::*;
52
53    #[test]
54    fn parse_args() -> anyhow::Result<()> {
55        serde_json::from_value::<Args>(
56                    json! {[{"type":"column","value":"test_cte"},{"type":"string","value":"output_test_name"}]},
57                ).context("Failed to parse parameters")?;
58        Ok(())
59    }
60}