wick_interface_types/signatures/
operation.rs1use serde::{Deserialize, Serialize};
2
3use crate::{contents_equal, Field, Type};
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize, Eq)]
7#[must_use]
8#[non_exhaustive]
9pub struct OperationSignature {
10 #[serde(default)]
12 pub name: String,
13
14 #[serde(default, skip_serializing_if = "Vec::is_empty")]
16 pub config: Vec<Field>,
17
18 #[serde(default)]
20 #[serde(skip_serializing_if = "Vec::is_empty")]
21 pub inputs: Vec<Field>,
22
23 #[serde(default)]
25 #[serde(skip_serializing_if = "Vec::is_empty")]
26 pub outputs: Vec<Field>,
27}
28
29impl PartialEq for OperationSignature {
30 fn eq(&self, other: &Self) -> bool {
31 self.name == other.name
32 && contents_equal(&self.inputs, &other.inputs)
33 && contents_equal(&self.outputs, &other.outputs)
34 }
35}
36
37impl OperationSignature {
38 pub fn new<T: Into<String>>(name: T, inputs: Vec<Field>, outputs: Vec<Field>, config: Vec<Field>) -> Self {
39 Self {
40 name: name.into(),
41 config,
42 inputs,
43 outputs,
44 }
45 }
46
47 #[must_use]
49 pub fn name(&self) -> &str {
50 &self.name
51 }
52
53 #[must_use]
55 pub fn config(&self) -> &[Field] {
56 &self.config
57 }
58
59 #[must_use]
61 pub fn inputs(&self) -> &[Field] {
62 &self.inputs
63 }
64
65 #[must_use]
67 pub fn outputs(&self) -> &[Field] {
68 &self.outputs
69 }
70
71 pub fn new_named<T: Into<String>>(name: T) -> Self {
73 Self {
74 name: name.into(),
75 ..Default::default()
76 }
77 }
78
79 pub fn add_input<T: Into<String>>(mut self, name: T, ty: Type) -> Self {
81 self.inputs.push(Field::new(name, ty));
82 self
83 }
84
85 pub fn add_output<T: Into<String>>(mut self, name: T, ty: Type) -> Self {
87 self.outputs.push(Field::new(name, ty));
88 self
89 }
90}