2021-11-30 14:30:13 +00:00
|
|
|
#[inline(always)]
|
2021-12-30 10:21:54 +00:00
|
|
|
#[cold]
|
|
|
|
pub const fn cold() {}
|
|
|
|
|
|
|
|
#[inline(always)]
|
2021-12-30 22:44:59 +00:00
|
|
|
#[allow(unused)]
|
2021-11-30 14:30:13 +00:00
|
|
|
pub const fn likely(b: bool) -> bool {
|
2021-12-30 10:21:54 +00:00
|
|
|
if !b {
|
2021-12-31 10:37:56 +00:00
|
|
|
cold();
|
2021-11-30 14:30:13 +00:00
|
|
|
}
|
2021-12-30 10:21:54 +00:00
|
|
|
b
|
2021-11-30 14:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
pub const fn unlikely(b: bool) -> bool {
|
2021-12-30 10:21:54 +00:00
|
|
|
if b {
|
2021-12-31 10:37:56 +00:00
|
|
|
cold();
|
2021-11-30 14:30:13 +00:00
|
|
|
}
|
2021-12-30 10:21:54 +00:00
|
|
|
b
|
2021-11-30 14:30:13 +00:00
|
|
|
}
|
2022-01-02 17:16:05 +00:00
|
|
|
|
|
|
|
pub trait Writer {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn write_one(self, v: u8) -> Self::Output;
|
|
|
|
fn write_many(self, v: &[u8]) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Writer for BytesMut<'a> {
|
|
|
|
type Output = BytesMut<'a>;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn write_one(self, v: u8) -> Self {
|
|
|
|
BytesMut::write_one(self, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn write_many(self, v: &[u8]) -> Self {
|
|
|
|
BytesMut::write_many(self, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct BytesMut<'a>(&'a mut [u8]);
|
|
|
|
|
|
|
|
impl<'a> BytesMut<'a> {
|
|
|
|
pub fn new(buf: &'a mut [u8]) -> Self {
|
|
|
|
Self(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn write_one(self, v: u8) -> Self {
|
|
|
|
if let Some((first, tail)) = self.0.split_first_mut() {
|
|
|
|
*first = v;
|
|
|
|
Self(tail)
|
|
|
|
} else {
|
|
|
|
cold();
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn write_many(self, v: &[u8]) -> Self {
|
|
|
|
let (head, tail) = self.0.split_at_mut(v.len());
|
|
|
|
head.copy_from_slice(v);
|
|
|
|
Self(tail)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub const fn len(&self) -> usize {
|
|
|
|
self.0.len()
|
|
|
|
}
|
|
|
|
}
|