async_flow/io/
port_direction.rs

1// This is free and unencumbered software released into the public domain.
2
3/// The dataflow direction of a port.
4#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
7pub enum PortDirection {
8    Input,
9    Output,
10}
11
12impl PortDirection {
13    /// Checks whether the port is an input port.
14    pub fn is_input(&self) -> bool {
15        *self == PortDirection::Input
16    }
17
18    /// Checks whether the port is an output port.
19    pub fn is_output(&self) -> bool {
20        *self == PortDirection::Output
21    }
22
23    pub fn as_str(&self) -> &str {
24        use PortDirection::*;
25        match self {
26            Input => "input",
27            Output => "output",
28        }
29    }
30}
31
32impl AsRef<str> for PortDirection {
33    fn as_ref(&self) -> &str {
34        self.as_str()
35    }
36}