#[cfg(test)]
mod test;
#[macro_export]
macro_rules! define_id {
($(#[$meta:meta])* $vis:vis struct $name:ident<$phantom:ident, $inner:ident>;) => {
$(#[$meta])*
$vis struct $name<$phantom, $inner> {
inner: $inner,
_phantom: ::std::marker::PhantomData<$phantom>,
}
impl<$phantom, $inner> $name<$phantom, $inner> {
pub fn new(inner: $inner) -> Self {
Self {
inner,
_phantom: ::std::marker::PhantomData,
}
}
pub fn inner(&self) -> &$inner {
&self.inner
}
}
impl<$phantom, $inner> $crate::KubetsuId for $name<$phantom, $inner> {
type Inner = $inner;
fn new(inner: $inner) -> Self {
Self {
inner,
_phantom: ::std::marker::PhantomData,
}
}
fn inner(&self) -> &$inner {
&self.inner
}
}
$crate::__impl_id_core_traits!([$phantom, $inner] $name<$phantom, $inner>, $inner);
};
($(#[$meta:meta])* $vis:vis struct $name:ident($inner:ty);) => {
$(#[$meta])*
$vis struct $name {
inner: $inner,
}
impl $name {
pub fn new(inner: $inner) -> Self {
Self { inner }
}
pub fn inner(&self) -> &$inner {
&self.inner
}
}
impl $crate::KubetsuId for $name {
type Inner = $inner;
fn new(inner: $inner) -> Self {
Self { inner }
}
fn inner(&self) -> &$inner {
&self.inner
}
}
$crate::__impl_id_core_traits!([] $name, $inner);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __impl_id_core_traits {
([] $name:ty, $inner:ty) => {
impl ::std::fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
self.inner().fmt(f)
}
}
impl ::std::cmp::PartialEq for $name {
fn eq(&self, other: &Self) -> bool {
self.inner().eq(other.inner())
}
}
impl ::std::cmp::Eq for $name {}
impl ::std::hash::Hash for $name {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.inner().hash(state)
}
}
impl ::std::clone::Clone for $name {
fn clone(&self) -> Self {
Self::new(self.inner().clone())
}
}
impl ::std::convert::From<$inner> for $name {
fn from(value: $inner) -> Self {
Self::new(value)
}
}
};
([$($gen:tt)+] $name:ty, $inner:ty) => {
impl<$($gen)+> ::std::fmt::Debug for $name where $inner: ::std::fmt::Debug {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
self.inner().fmt(f)
}
}
impl<$($gen)+> ::std::cmp::PartialEq for $name where $inner: ::std::cmp::PartialEq {
fn eq(&self, other: &Self) -> bool {
self.inner().eq(other.inner())
}
}
impl<$($gen)+> ::std::cmp::Eq for $name where $inner: ::std::cmp::Eq {}
impl<$($gen)+> ::std::hash::Hash for $name where $inner: ::std::cmp::PartialEq + ::std::hash::Hash {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.inner().hash(state)
}
}
impl<$($gen)+> ::std::clone::Clone for $name where $inner: ::std::clone::Clone {
fn clone(&self) -> Self {
Self::new(self.inner().clone())
}
}
impl<$($gen)+> ::std::convert::From<$inner> for $name {
fn from(value: $inner) -> Self {
Self::new(value)
}
}
};
}