more cleanup

This commit is contained in:
nora 2022-02-26 23:24:08 +01:00
parent 6d944e1265
commit de027d9f5a
9 changed files with 46 additions and 14 deletions

View file

@ -12,18 +12,22 @@ newtype_id!(pub ChannelId);
pub struct ChannelNum(u16);
impl ChannelNum {
#[must_use]
pub fn new(num: u16) -> Self {
Self(num)
}
#[must_use]
pub fn num(self) -> u16 {
self.0
}
#[must_use]
pub fn is_zero(self) -> bool {
self.0 == 0
}
#[must_use]
pub fn zero() -> Self {
Self(0)
}
@ -47,6 +51,7 @@ pub struct Connection {
}
impl Connection {
#[must_use]
pub fn new_handle(
id: ConnectionId,
peer_addr: SocketAddr,
@ -78,6 +83,7 @@ pub struct Channel {
}
impl Channel {
#[must_use]
pub fn new_handle(
id: ChannelId,
num: u16,

View file

@ -3,8 +3,9 @@ macro_rules! newtype_id {
($vis:vis $name:ident) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
$vis struct $name(::uuid::Uuid);
impl $name {
#[must_use]
pub fn random() -> Self {
::rand::random()
}
@ -24,6 +25,32 @@ macro_rules! newtype_id {
};
}
#[macro_export]
macro_rules! newtype {
($(#[$meta:meta])* $vis:vis $name:ident: $ty:ty) => {
$(#[$meta])*
$vis struct $name($ty);
impl $name {
pub fn new(inner: $ty) -> Self {
Self(inner)
}
pub fn into_inner(self) -> $ty {
self.0
}
}
impl std::ops::Deref for $name {
type Target = $ty;
fn deref(&self) -> &Self::Target {
&self.0
}
}
};
}
#[macro_export]
macro_rules! amqp_todo {
() => {