alloy_primitives/bits/
rkyv.rs1use super::*;
2use core::{
3 fmt::{Debug, Formatter},
4 hash::Hash,
5};
6
7impl From<ArchivedAddress> for Address {
8 fn from(archived: ArchivedAddress) -> Self {
9 Self::from(archived.0.0)
10 }
11}
12
13impl Debug for ArchivedAddress {
14 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
15 Debug::fmt(&Address::from(self.0.0), f)
16 }
17}
18
19impl From<ArchivedBloom> for Bloom {
20 fn from(archived: ArchivedBloom) -> Self {
21 Self::from(archived.0.0)
22 }
23}
24
25impl Debug for ArchivedBloom {
26 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
27 Debug::fmt(&Bloom::from(self.0.0), f)
28 }
29}
30
31impl<const N: usize> From<ArchivedFixedBytes<N>> for FixedBytes<N> {
32 fn from(archived: ArchivedFixedBytes<N>) -> Self {
33 Self(archived.0)
34 }
35}
36
37impl<const N: usize> Debug for ArchivedFixedBytes<N> {
38 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
39 Debug::fmt(&FixedBytes(self.0), f)
40 }
41}
42
43impl<const N: usize> Copy for ArchivedFixedBytes<N> {}
44
45impl<const N: usize> Clone for ArchivedFixedBytes<N> {
46 fn clone(&self) -> Self {
47 *self
48 }
49}
50
51impl<const N: usize> PartialEq for ArchivedFixedBytes<N> {
52 fn eq(&self, other: &Self) -> bool {
53 self.0 == other.0
54 }
55}
56
57impl<const N: usize> Eq for ArchivedFixedBytes<N> {}
58
59impl<const N: usize> Hash for ArchivedFixedBytes<N> {
60 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
61 self.0.hash(state)
62 }
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68 use ::rkyv::rancor;
69
70 #[test]
71 fn rkyv_roundtrip() {
72 let bytes = FixedBytes([0, 0, 0, 0, 1, 35, 69, 103, 137, 171, 205, 239]);
73 let ser = ::rkyv::to_bytes::<rancor::BoxedError>(&bytes).unwrap();
74 let archived = ::rkyv::access::<ArchivedFixedBytes<12>, rancor::BoxedError>(&ser).unwrap();
75
76 assert_eq!(bytes, FixedBytes::from(*archived));
77
78 let des = ::rkyv::deserialize::<_, rancor::BoxedError>(archived).unwrap();
79 assert_eq!(bytes, des);
80 }
81}