bee_network/network/
origin.rs1use std::fmt;
5
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum Origin {
9 Inbound,
11 Outbound,
13}
14
15impl Origin {
16 pub fn is_inbound(&self) -> bool {
18 matches!(self, Self::Inbound)
19 }
20
21 pub fn is_outbound(&self) -> bool {
23 matches!(self, Self::Outbound)
24 }
25}
26
27impl fmt::Display for Origin {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match *self {
30 Origin::Inbound => f.write_str("inbound"),
31 Origin::Outbound => f.write_str("outbound"),
32 }
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn is_api() {
42 let mut origin = Origin::Inbound;
43 assert!(origin.is_inbound());
44
45 origin = Origin::Outbound;
46 assert!(origin.is_outbound());
47 }
48
49 #[test]
50 fn display() {
51 assert_eq!(&Origin::Inbound.to_string(), "inbound");
52 assert_eq!(&Origin::Outbound.to_string(), "outbound");
53 }
54}