1pub use candid;
8
9pub mod bounded_cell;
10pub mod serialize;
11pub mod structures;
12pub mod types;
13pub mod utils;
14
15#[macro_export]
22macro_rules! impl_storable_bounded {
23 ($ident:ident, $max_size:expr, $is_fixed_size:expr) => {
24 impl $crate::cdk::structures::storable::Storable for $ident {
25 const BOUND: $crate::cdk::structures::storable::Bound =
26 $crate::cdk::structures::storable::Bound::Bounded {
27 max_size: $max_size,
28 is_fixed_size: $is_fixed_size,
29 };
30
31 fn to_bytes(&self) -> ::std::borrow::Cow<'_, [u8]> {
32 let bytes = $crate::cdk::serialize::serialize(self).unwrap_or_else(|err| {
33 panic!("impl_storable_bounded: serialize failed: {err}");
34 });
35
36 ::std::borrow::Cow::Owned(bytes)
37 }
38
39 fn into_bytes(self) -> Vec<u8> {
40 $crate::cdk::serialize::serialize(&self).unwrap_or_else(|err| {
41 panic!("impl_storable_bounded: serialize failed: {err}");
42 })
43 }
44
45 fn from_bytes(bytes: ::std::borrow::Cow<'_, [u8]>) -> Self {
46 $crate::cdk::serialize::deserialize(&bytes).unwrap_or_else(|err| {
47 panic!("impl_storable_bounded: deserialize failed: {err}");
48 })
49 }
50 }
51 };
52}
53
54#[macro_export]
61macro_rules! impl_storable_unbounded {
62 ($ident:ident) => {
63 impl $crate::cdk::structures::storable::Storable for $ident {
64 const BOUND: $crate::cdk::structures::storable::Bound =
65 $crate::cdk::structures::storable::Bound::Unbounded;
66
67 fn to_bytes(&self) -> ::std::borrow::Cow<'_, [u8]> {
68 let bytes = $crate::cdk::serialize::serialize(self).unwrap_or_else(|err| {
69 panic!("impl_storable_unbounded: serialize failed: {err}");
70 });
71
72 ::std::borrow::Cow::Owned(bytes)
73 }
74
75 fn into_bytes(self) -> Vec<u8> {
76 $crate::cdk::serialize::serialize(&self).unwrap_or_else(|err| {
77 panic!("impl_storable_unbounded: serialize failed: {err}");
78 })
79 }
80
81 fn from_bytes(bytes: ::std::borrow::Cow<'_, [u8]>) -> Self {
82 $crate::cdk::serialize::deserialize(&bytes).unwrap_or_else(|err| {
83 panic!("impl_storable_unbounded: deserialize failed: {err}");
84 })
85 }
86 }
87 };
88}