unc_sdk/private/mod.rs
1#[cfg(feature = "abi")]
2pub use unc_abi::__private::ChunkedAbiEntry;
3#[cfg(feature = "abi")]
4pub use unc_abi::{
5 AbiBorshParameter, AbiFunction, AbiFunctionKind, AbiFunctionModifier, AbiJsonParameter,
6 AbiParameters, AbiType,
7};
8#[cfg(feature = "abi")]
9mod result_type_ext;
10
11#[cfg(feature = "abi")]
12pub use result_type_ext::ResultTypeExt;
13
14use crate::IntoStorageKey;
15use borsh::{to_vec, BorshSerialize};
16
17/// Converts a Borsh serializable object into a `Vec<u8>` that is used for a storage key.
18///
19/// [`BorshStorageKey`](crate::BorshStorageKey) should be used instead of implementing
20/// this manually.
21///
22/// ```
23/// use unc_sdk::borsh::BorshSerialize;
24/// use unc_sdk::BorshStorageKey;
25/// use unc_sdk::collections::LookupMap;
26///
27/// #[derive(BorshSerialize, BorshStorageKey)]
28/// enum StorageKey {
29/// FungibleToken,
30/// Metadata { sub_key: String },
31/// }
32///
33/// let lookup_map_1: LookupMap<u64, String> = LookupMap::new(StorageKey::Metadata { sub_key: String::from("yo") });
34/// let lookup_map_2: LookupMap<String, String> = LookupMap::new(StorageKey::FungibleToken);
35/// ```
36pub trait BorshIntoStorageKey: BorshSerialize {}
37
38impl<T> IntoStorageKey for T
39where
40 T: BorshIntoStorageKey,
41{
42 fn into_storage_key(self) -> Vec<u8> {
43 to_vec(&self).unwrap()
44 }
45}