use serde::{Deserialize, Serialize};
#[derive(
Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug,
)]
#[serde(transparent)]
pub struct Int(i64);
impl Int {
pub const fn new(value: i64) -> Self {
Self(value)
}
pub const fn into_inner(self) -> i64 {
self.0
}
}
impl From<i64> for Int {
fn from(value: i64) -> Self {
Self::new(value)
}
}
impl From<Int> for i64 {
fn from(value: Int) -> Self {
value.into_inner()
}
}
impl std::ops::Deref for Int {
type Target = i64;
fn deref(&self) -> &i64 {
&self.0
}
}
impl std::ops::DerefMut for Int {
fn deref_mut(&mut self) -> &mut i64 {
&mut self.0
}
}
#[cfg(test)]
mod tests {
use crate::{decode, encode};
use super::*;
#[test]
fn wire_shape_is_identical_to_a_bare_i64() {
assert_eq!(encode(&Int::new(7)).unwrap(), encode(&7_i64).unwrap());
assert_eq!(decode::<i64>(&encode(&Int::new(7)).unwrap()).unwrap(), 7);
assert_eq!(
decode::<Int>(&encode(&7_i64).unwrap()).unwrap(),
Int::new(7)
);
}
}