use std::ops::BitOr;
#[derive(Debug, Copy, Clone)]
pub struct Info {
pub name: &'static str,
pub kind: Kind,
}
#[derive(Debug, Clone, Copy)]
pub struct Kind(usize);
#[allow(non_upper_case_globals)]
impl Kind {
pub const Ignite: Kind = Kind(1 << 0);
pub const Liftoff: Kind = Kind(1 << 1);
pub const Request: Kind = Kind(1 << 2);
pub const Response: Kind = Kind(1 << 3);
pub const Shutdown: Kind = Kind(1 << 4);
pub const Singleton: Kind = Kind(1 << 5);
#[inline]
pub fn is(self, other: Kind) -> bool {
(other.0 & self.0) == other.0
}
#[inline]
pub fn is_exactly(self, other: Kind) -> bool {
self.0 == other.0
}
}
impl BitOr for Kind {
type Output = Self;
#[inline(always)]
fn bitor(self, rhs: Self) -> Self {
Kind(self.0 | rhs.0)
}
}
impl std::fmt::Display for Kind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut is_first = true;
let mut write = |string, kind| {
if self.is(kind) {
if !is_first { f.write_str(", ")?; }
f.write_str(string)?;
is_first = false;
}
Ok(())
};
write("ignite", Kind::Ignite)?;
write("liftoff", Kind::Liftoff)?;
write("request", Kind::Request)?;
write("response", Kind::Response)?;
write("shutdown", Kind::Shutdown)?;
write("singleton", Kind::Singleton)
}
}