1use crate::atom::{Atom, BitAtom, IntAtom};
2use crate::Atomic;
3
4pub trait Atomizable {
6 type Atom: Atom;
8
9 fn pack(self) -> Self::Atom;
11
12 fn unpack(atom: Self::Atom) -> Self;
14}
15
16impl<T: Atom> Atomizable for T {
17 type Atom = T;
18
19 fn pack(self) -> Self::Atom {
20 self
21 }
22
23 fn unpack(atom: Self::Atom) -> Self {
24 atom
25 }
26}
27
28pub trait BitAtomizable: Atomizable<Atom: BitAtom> {}
30
31impl<T: BitAtom> BitAtomizable for T {}
32
33pub trait IntAtomizable: Atomizable<Atom: IntAtom> {}
35
36impl<T: IntAtom> IntAtomizable for T {}
37
38pub trait Atomize: Atomizable + Sized {
42 type Atom: Atom;
44
45 fn atomize(self) -> Atomic<Self>;
47}
48
49impl<T: Atomizable> Atomize for T {
50 type Atom = T::Atom;
51
52 fn atomize(self) -> Atomic<Self> {
53 Atomic::from(self)
54 }
55}