limithub_code_block_sdk/
port.rs

1use crate::value::{PortValue, PortValueType};
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7pub struct Port {
8    id: String,
9    pub(crate) name: String,
10    port_value_type: PortValueType,
11    default_value: Option<PortValue>,
12}
13
14impl Port {
15    pub fn new(name: impl AsRef<str>, value_type: PortValueType) -> Self {
16        Port {
17            // determined by frontend
18            id: String::new(),
19            name: name.as_ref().to_owned(),
20            port_value_type: value_type,
21            default_value: None,
22        }
23    }
24
25    pub fn with_default_value(self, default_value: PortValue) -> Self {
26        Self {
27            default_value: Some(default_value),
28            ..self
29        }
30    }
31}
32
33impl std::cmp::PartialEq for Port {
34    fn eq(&self, other: &Self) -> bool {
35        self.name.eq(&other.name)
36    }
37}
38
39impl std::cmp::Eq for Port {}
40
41impl std::cmp::PartialOrd for Port {
42    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
43        self.name.partial_cmp(&other.name)
44    }
45}
46
47impl std::cmp::Ord for Port {
48    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
49        self.name.cmp(&other.name)
50    }
51}