near_sdk/utils/
storage_key_impl.rs

1/// Converts Self into a [`Vec<u8>`] that is used for a storage key through [`into_storage_key`].
2///
3/// [`into_storage_key`]: IntoStorageKey::into_storage_key
4///
5/// More information about storage is in [NEAR documentation](https://docs.near.org/build/smart-contracts/anatomy/storage).
6pub trait IntoStorageKey {
7    /// Consumes self and returns [`Vec<u8>`] bytes which are used as a storage key.
8    fn into_storage_key(self) -> Vec<u8>;
9}
10
11impl IntoStorageKey for Vec<u8> {
12    #[inline]
13    fn into_storage_key(self) -> Vec<u8> {
14        self
15    }
16}
17
18impl<'a> IntoStorageKey for &'a [u8] {
19    #[inline]
20    fn into_storage_key(self) -> Vec<u8> {
21        self.to_vec()
22    }
23}
24
25impl<'a> IntoStorageKey for &'a [u8; 1] {
26    #[inline]
27    fn into_storage_key(self) -> Vec<u8> {
28        self.to_vec()
29    }
30}
31
32impl IntoStorageKey for u8 {
33    #[inline]
34    fn into_storage_key(self) -> Vec<u8> {
35        vec![self]
36    }
37}