use super::newtype::NewtypeOf;
#[diagnostic::on_unimplemented(
message = "`{Self}` cannot be used as a `#[version]` field",
label = "invalid type for `#[version]`",
note = "only `u64` and tuple-newtype embeds of `u64` are supported"
)]
pub trait Version: Copy {
fn as_u64(self) -> u64;
fn from_u64(v: u64) -> Self;
}
impl Version for u64 {
fn as_u64(self) -> u64 {
self
}
fn from_u64(v: u64) -> Self {
v
}
}
#[diagnostic::do_not_recommend]
impl<T> Version for T
where
T: NewtypeOf + Copy,
<T as NewtypeOf>::Inner: Version,
{
fn as_u64(self) -> u64 {
self.into_inner().as_u64()
}
fn from_u64(v: u64) -> Self {
T::from_inner(<T::Inner as Version>::from_u64(v))
}
}