async_flow/io/
port_direction.rs

1// This is free and unencumbered software released into the public domain.
2
3/// A port's dataflow direction (either input or output).
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 == Self::Input
16    }
17
18    /// Checks whether the port is an output port.
19    pub fn is_output(&self) -> bool {
20        *self == Self::Output
21    }
22
23    pub fn as_str(&self) -> &str {
24        match self {
25            Self::Input => "input",
26            Self::Output => "output",
27        }
28    }
29}
30
31impl AsRef<str> for PortDirection {
32    fn as_ref(&self) -> &str {
33        self.as_str()
34    }
35}