use core::ops::{BitOr, BitOrAssign};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(transparent)]
pub struct TcpFlags(u8);
impl TcpFlags {
pub const FIN: Self = Self(1);
pub const SYN: Self = Self(2);
pub const RST: Self = Self(4);
pub const PSH: Self = Self(8);
pub const ACK: Self = Self(16);
pub const URG: Self = Self(32);
pub const ECE: Self = Self(64);
pub const CWR: Self = Self(128);
pub const fn new(raw: u8) -> Self {
Self(raw)
}
pub const fn raw(self) -> u8 {
self.0
}
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
}
impl BitOr for TcpFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
self.union(rhs)
}
}
impl BitOrAssign for TcpFlags {
fn bitor_assign(&mut self, rhs: Self) {
*self = self.union(rhs);
}
}