use core ::ops :: { BitOr, BitAnd, Not };
#[ derive( Debug, Clone, Copy, PartialEq, Eq, Default ) ]
pub struct SplitFlags(pub u8);
impl SplitFlags
{
pub const PRESERVING_EMPTY: SplitFlags = SplitFlags(1 << 0);
pub const PRESERVING_DELIMITERS: SplitFlags = SplitFlags(1 << 1);
pub const PRESERVING_QUOTING: SplitFlags = SplitFlags(1 << 2);
pub const STRIPPING: SplitFlags = SplitFlags(1 << 3);
pub const QUOTING: SplitFlags = SplitFlags(1 << 4);
#[ must_use ]
pub const fn from_bits(bits: u8) -> Option< Self >
{
Some(Self(bits))
}
#[ must_use ]
pub const fn bits( &self ) -> u8
{
self.0
}
#[ must_use ]
pub const fn contains(&self, other: Self) -> bool
{
(self.0 & other.0) == other.0
}
pub fn insert(&mut self, other: Self)
{
self.0 |= other.0;
}
pub fn remove(&mut self, other: Self)
{
self.0 &= !other.0;
}
}
impl BitOr for SplitFlags
{
type Output = Self;
fn bitor(self, rhs: Self) -> Self ::Output
{
Self(self.0 | rhs.0)
}
}
impl BitAnd for SplitFlags
{
type Output = Self;
fn bitand(self, rhs: Self) -> Self ::Output
{
Self(self.0 & rhs.0)
}
}
impl Not for SplitFlags
{
type Output = Self;
fn not(self) -> Self ::Output
{
Self(!self.0)
}
}
impl From< u8 > for SplitFlags
{
fn from(value: u8) -> Self
{
Self(value)
}
}
impl From< SplitFlags > for u8
{
fn from(value: SplitFlags) -> Self
{
value.0
}
}