Compare commits
3 Commits
84c3cada2c
...
0bedbc1195
Author | SHA1 | Date |
---|---|---|
|
0bedbc1195 | |
|
73a706b856 | |
|
9ee5fad44a |
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tide_tracing"
|
||||
version = "0.6.3"
|
||||
version = "0.7.0"
|
||||
authors = ["Michael Pfaff <michael@pfaff.dev>"]
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
@ -10,4 +10,4 @@ nrid = { git = "https://git.pfaff.dev/michael/nrid.rs.git", tag = "v0.2.0", defa
|
|||
tide = { version = "0.16", default-features = false }
|
||||
tracing = "0.1"
|
||||
async-trait = "0.1"
|
||||
num_enum = "0.5"
|
||||
num_enum = "0.7"
|
||||
|
|
47
src/lib.rs
47
src/lib.rs
|
@ -1,5 +1,3 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
|
@ -29,38 +27,47 @@ pub struct ReqComps(u8);
|
|||
impl ReqComps {
|
||||
#[inline]
|
||||
pub const fn contains(self, mask: ReqComp) -> bool {
|
||||
(self & mask).0 == mask as u8
|
||||
self.bitand_one(mask).0 == mask as u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn contains_all(self, mask: ReqComps) -> bool {
|
||||
self & mask == mask
|
||||
pub const fn contains_all(self, mask: Self) -> bool {
|
||||
self.bitand_self(mask).0 == mask.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
const fn bitand_self(self, rhs: Self) -> Self {
|
||||
Self((self.0 as u8) & (rhs.0 as u8))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
const fn bitand_one(self, rhs: ReqComp) -> Self {
|
||||
Self((self.0 as u8) & (rhs as u8))
|
||||
}
|
||||
}
|
||||
|
||||
impl const Default for ReqComps {
|
||||
impl Default for ReqComps {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
|
||||
// unfortunately, the automatic Into impl will not be const.
|
||||
impl const From<ReqComp> for ReqComps {
|
||||
impl From<ReqComp> for ReqComps {
|
||||
#[inline]
|
||||
fn from(comp: ReqComp) -> Self {
|
||||
Self(comp as u8)
|
||||
}
|
||||
}
|
||||
|
||||
impl const core::cmp::PartialEq for ReqComps {
|
||||
impl core::cmp::PartialEq for ReqComps {
|
||||
#[inline]
|
||||
fn eq(&self, comp: &Self) -> bool {
|
||||
self.0 == comp.0
|
||||
}
|
||||
}
|
||||
|
||||
impl const core::ops::BitOr for ReqComp {
|
||||
impl core::ops::BitOr for ReqComp {
|
||||
type Output = ReqComps;
|
||||
|
||||
#[inline]
|
||||
|
@ -69,16 +76,16 @@ impl const core::ops::BitOr for ReqComp {
|
|||
}
|
||||
}
|
||||
|
||||
impl const core::ops::BitOr for ReqComps {
|
||||
impl core::ops::BitOr for ReqComps {
|
||||
type Output = ReqComps;
|
||||
|
||||
#[inline]
|
||||
fn bitor(self, rhs: Self) -> Self::Output {
|
||||
ReqComps((self.0 as u8) | (rhs.0 as u8))
|
||||
ReqComps(self.0 | rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl const core::ops::BitOr<ReqComp> for ReqComps {
|
||||
impl core::ops::BitOr<ReqComp> for ReqComps {
|
||||
type Output = ReqComps;
|
||||
|
||||
#[inline]
|
||||
|
@ -87,7 +94,6 @@ impl const core::ops::BitOr<ReqComp> for ReqComps {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO make `const` when is "stable" #57349 <https://github.com/rust-lang/rust/issues/57349>
|
||||
impl core::ops::BitOrAssign for ReqComps {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, rhs: ReqComps) {
|
||||
|
@ -95,7 +101,6 @@ impl core::ops::BitOrAssign for ReqComps {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO make `const` when is "stable" #57349 <https://github.com/rust-lang/rust/issues/57349>
|
||||
impl core::ops::BitOrAssign<ReqComp> for ReqComps {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, rhs: ReqComp) {
|
||||
|
@ -103,7 +108,7 @@ impl core::ops::BitOrAssign<ReqComp> for ReqComps {
|
|||
}
|
||||
}
|
||||
|
||||
impl const core::ops::BitAnd for ReqComp {
|
||||
impl core::ops::BitAnd for ReqComp {
|
||||
type Output = ReqComps;
|
||||
|
||||
#[inline]
|
||||
|
@ -112,21 +117,21 @@ impl const core::ops::BitAnd for ReqComp {
|
|||
}
|
||||
}
|
||||
|
||||
impl const core::ops::BitAnd for ReqComps {
|
||||
impl core::ops::BitAnd for ReqComps {
|
||||
type Output = ReqComps;
|
||||
|
||||
#[inline]
|
||||
fn bitand(self, rhs: Self) -> Self::Output {
|
||||
ReqComps((self.0 as u8) & (rhs.0 as u8))
|
||||
self.bitand_self(rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl const core::ops::BitAnd<ReqComp> for ReqComps {
|
||||
impl core::ops::BitAnd<ReqComp> for ReqComps {
|
||||
type Output = ReqComps;
|
||||
|
||||
#[inline]
|
||||
fn bitand(self, rhs: ReqComp) -> Self::Output {
|
||||
ReqComps((self.0 as u8) & (rhs as u8))
|
||||
self.bitand_one(rhs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +156,7 @@ pub struct LogMiddleware {
|
|||
pub components: ReqComps,
|
||||
}
|
||||
|
||||
impl const Default for LogMiddleware {
|
||||
impl Default for LogMiddleware {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
Loading…
Reference in New Issue