use alloc::string::{String, ToString};
use crate::error::GraphError;
use crate::id::PortId;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PortDirection {
Input,
Output,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Port {
id: PortId,
direction: PortDirection,
type_tag: String,
}
impl Port {
pub fn new(id: PortId, direction: PortDirection, type_tag: &str) -> Result<Self, GraphError> {
if type_tag.is_empty() {
return Err(GraphError::EmptyTypeTag);
}
Ok(Self {
id,
direction,
type_tag: type_tag.to_string(),
})
}
pub fn id(&self) -> &PortId {
&self.id
}
pub const fn direction(&self) -> PortDirection {
self.direction
}
pub fn type_tag(&self) -> &str {
self.type_tag.as_str()
}
}