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
#![allow(missing_docs)] // delete when we move away from the `property` crate.

use config::common::OperationDefinition;
use wick_interface_types::{OperationSignatures, TypeDefinition};

use crate::config::components::ComponentConfig;
use crate::config::{self};

#[derive(Debug, Default, Clone, derive_asset_container::AssetManager, property::Property, serde::Serialize)]
#[property(get(public), set(private), mut(disable))]
#[asset(asset(crate::config::AssetReference))]
#[must_use]
/// The Wick representation of an interface.
pub struct InterfaceDefinition {
  /// Types used by the interface's operations.
  #[asset(skip)]
  #[serde(skip_serializing_if = "Vec::is_empty")]
  pub(crate) types: Vec<TypeDefinition>,

  /// The operations the interface exposes.
  #[asset(skip)]
  #[property(skip)]
  #[serde(skip_serializing_if = "Vec::is_empty")]
  pub(crate) operations: Vec<OperationDefinition>,
}

impl ComponentConfig for InterfaceDefinition {
  type Operation = OperationDefinition;

  fn operations(&self) -> &[Self::Operation] {
    &self.operations
  }

  fn operations_mut(&mut self) -> &mut Vec<Self::Operation> {
    &mut self.operations
  }
}

impl OperationSignatures for InterfaceDefinition {
  fn operation_signatures(&self) -> Vec<wick_interface_types::OperationSignature> {
    self.operations.iter().cloned().map(Into::into).collect()
  }
}