/ src / item.rs
item.rs
 1  use candid::{CandidType, Decode, Deserialize, Encode};
 2  use ic_stable_structures::{storable::Bound, Storable};
 3  use shared::{
 4      item::{attr::Stock, ItemId, ItemName},
 5      unit::{Currency, Price},
 6  };
 7  use std::{borrow::Cow, collections::BTreeMap};
 8  
 9  #[derive(CandidType, Deserialize, Debug, Clone)]
10  pub enum ItemFluctuateData {
11      V1 {
12          id: ItemId,
13          name: ItemName,
14          stock: Stock,
15          price: BTreeMap<Currency, Price>,
16      },
17  }
18  
19  impl Storable for ItemFluctuateData {
20      fn to_bytes(&self) -> std::borrow::Cow<[u8]> {
21          Cow::Owned(Encode!(self).unwrap())
22      }
23  
24      fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self {
25          Decode!(bytes.as_ref(), Self).unwrap()
26      }
27  
28      const BOUND: Bound = Bound::Unbounded;
29  }