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