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
62
63
64
65
66
67
use std::str::FromStr;

use serde::ser::SerializeMap;
use serde::{Deserialize, Serialize, Serializer};

mod flow_ast;
mod interface_types;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LocationReference(pub(super) String);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

pub struct Glob(pub(super) String);

#[allow(clippy::from_over_into)]
impl Into<String> for super::TypeSignature {
  fn into(self) -> String {
    let ty: wick_interface_types::Type = self.try_into().unwrap();
    ty.to_string()
  }
}

#[allow(clippy::from_over_into)]
impl Into<String> for super::ConnectionDefinition {
  fn into(self) -> String {
    let ty: flow_expression_parser::ast::ConnectionExpression = self.try_into().unwrap();
    ty.to_string()
  }
}

#[allow(clippy::from_over_into)]
impl Into<String> for super::ComponentReference {
  fn into(self) -> String {
    self.id
  }
}

pub(super) fn serialize_component_expression<S>(
  value: &super::ComponentOperationExpression,
  s: S,
) -> Result<S::Ok, S::Error>
where
  S: Serializer,
{
  let name = match &value.component {
    super::ComponentDefinition::ComponentReference(r) => &r.id,
    _ => return value.serialize(s),
  };

  if value.with.is_none() {
    s.serialize_str(&format!("{}::{}", name, value.name))
  } else {
    let mut m = if value.timeout.is_some() {
      s.serialize_map(Some(4))?
    } else {
      s.serialize_map(Some(3))?
    };
    m.serialize_entry("name", &value.name)?;
    m.serialize_entry("component", &name)?;
    m.serialize_entry("with", &value.with)?;
    if let Some(timeout) = &value.timeout {
      m.serialize_entry("timeout", timeout)?;
    }
    m.end()
  }
}