1use alloc::string::{String, ToString};
2
3use crate::error::GraphError;
4use crate::id::PortId;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum PortDirection {
9 Input,
10 Output,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct Port {
16 id: PortId,
17 direction: PortDirection,
18 type_tag: String,
19}
20
21impl Port {
22 pub fn new(id: PortId, direction: PortDirection, type_tag: &str) -> Result<Self, GraphError> {
24 if type_tag.is_empty() {
25 return Err(GraphError::EmptyTypeTag);
26 }
27
28 Ok(Self {
29 id,
30 direction,
31 type_tag: type_tag.to_string(),
32 })
33 }
34
35 pub fn id(&self) -> &PortId {
37 &self.id
38 }
39
40 pub const fn direction(&self) -> PortDirection {
42 self.direction
43 }
44
45 pub fn type_tag(&self) -> &str {
47 self.type_tag.as_str()
48 }
49}