Skip to content

Commit 5d78ffb

Browse files
author
BiancaIalangi
committed
storage v2 - replace DynamicKey with StorageKey
1 parent 145e7ed commit 5d78ffb

File tree

4 files changed

+17
-50
lines changed

4 files changed

+17
-50
lines changed

framework/base/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod types;
3434

3535
#[cfg(feature = "std")]
3636
mod std_impl;
37+
mod storage_v2;
3738

3839
pub use hex_call_data::*;
3940
pub use hex_literal;

framework/base/src/storage_v2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ mod key;
33

44
#[allow(unused_imports)]
55
pub use context::*;
6+
#[allow(unused_imports)]
67
pub use key::*;

framework/base/src/storage_v2/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66
StorageWriteApiImpl as _,
77
},
88
storage::StorageKey,
9-
storage_v2::DynamicKey,
109
types::{ManagedBuffer, ManagedType},
1110
};
1211

@@ -128,7 +127,7 @@ pub struct SelfRead<'r, M>
128127
where
129128
M: ManagedTypeApi + ErrorApi + 'static,
130129
{
131-
key: DynamicKey<M>,
130+
key: StorageKey<M>,
132131
_phantom: PhantomData<&'r ()>,
133132
}
134133

@@ -137,7 +136,7 @@ impl<M> SelfRead<'_, M>
137136
where
138137
M: ManagedTypeApi + ErrorApi + 'static,
139138
{
140-
pub fn new(key: DynamicKey<M>) -> Self {
139+
pub fn new(key: StorageKey<M>) -> Self {
141140
SelfRead {
142141
key,
143142
_phantom: PhantomData,
@@ -194,7 +193,7 @@ pub struct SelfWrite<'w, M>
194193
where
195194
M: ManagedTypeApi + ErrorApi + 'static,
196195
{
197-
key: DynamicKey<M>,
196+
key: StorageKey<M>,
198197
_phantom: PhantomData<&'w mut ()>,
199198
}
200199

@@ -203,7 +202,7 @@ impl<M> SelfWrite<'_, M>
203202
where
204203
M: ManagedTypeApi + ErrorApi + 'static,
205204
{
206-
pub fn new(key: DynamicKey<M>) -> Self {
205+
pub fn new(key: StorageKey<M>) -> Self {
207206
SelfWrite {
208207
key,
209208
_phantom: PhantomData,

framework/base/src/storage_v2/key.rs

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,28 @@ use crate::{
1515
types::{ManagedBuffer, ManagedType},
1616
};
1717

18-
#[derive(Default, Clone)]
19-
pub struct DynamicKey<A>(StorageKey<A>)
20-
where
21-
A: ManagedTypeApi + ErrorApi + 'static;
22-
23-
impl<A> PartialEq for DynamicKey<A>
24-
where
25-
A: ManagedTypeApi + ErrorApi + 'static,
26-
{
27-
fn eq(&self, other: &Self) -> bool {
28-
self.0.eq(&other.0)
29-
}
30-
}
31-
32-
impl<A> Deref for DynamicKey<A>
33-
where
34-
A: ManagedTypeApi + ErrorApi + 'static,
35-
{
36-
type Target = StorageKey<A>;
37-
38-
fn deref(&self) -> &Self::Target {
39-
&self.0
40-
}
41-
}
42-
43-
impl<A> DerefMut for DynamicKey<A>
44-
where
45-
A: ManagedTypeApi + ErrorApi + 'static,
46-
{
47-
fn deref_mut(&mut self) -> &mut Self::Target {
48-
&mut self.0
49-
}
50-
}
51-
5218
#[allow(dead_code)]
5319
pub trait Key<A>: 'static
5420
where
5521
A: ManagedTypeApi + ErrorApi + 'static,
5622
{
57-
fn full_key(&self) -> DynamicKey<A>;
23+
fn full_key(&self) -> StorageKey<A>;
5824

5925
fn key_eq<Other: Key<A>>(&self, other: &Other) -> bool {
6026
self.full_key().eq(&other.full_key())
6127
}
6228

63-
fn append_to(&self, target: &mut DynamicKey<A>) {
29+
fn append_to(&self, target: &mut StorageKey<A>) {
6430
target.append_bytes(b".");
6531
target.append_managed_buffer(&self.full_key().buffer);
6632
}
6733
}
6834

69-
impl<A> Key<A> for DynamicKey<A>
35+
impl<A> Key<A> for StorageKey<A>
7036
where
7137
A: ManagedTypeApi + ErrorApi + 'static,
7238
{
73-
fn full_key(&self) -> DynamicKey<A> {
39+
fn full_key(&self) -> StorageKey<A> {
7440
self.clone()
7541
}
7642
}
@@ -113,8 +79,8 @@ impl<A> Key<A> for StrKey
11379
where
11480
A: ManagedTypeApi + ErrorApi + 'static,
11581
{
116-
fn full_key(&self) -> DynamicKey<A> {
117-
DynamicKey(StorageKey::new(self.as_bytes()))
82+
fn full_key(&self) -> StorageKey<A> {
83+
StorageKey::new(self.as_bytes())
11884
}
11985
}
12086

@@ -198,7 +164,7 @@ where
198164
}
199165
}
200166

201-
pub fn root_path(self, root_key: &DynamicKey<A>) -> SelfStorageRef<'a, A> {
167+
pub fn root_path(self, root_key: &StorageKey<A>) -> SelfStorageRef<'a, A> {
202168
SelfStorageRef {
203169
source_ref: self,
204170
key: root_key.to_owned(),
@@ -229,7 +195,7 @@ where
229195
}
230196
}
231197

232-
pub fn root_path(self, root_key: &DynamicKey<A>) -> SelfStorageRefMut<'a, A> {
198+
pub fn root_path(self, root_key: &StorageKey<A>) -> SelfStorageRefMut<'a, A> {
233199
SelfStorageRefMut {
234200
source_ref: self,
235201
key: root_key.to_owned(),
@@ -258,7 +224,7 @@ where
258224
A: ManagedTypeApi + ErrorApi + 'static,
259225
{
260226
pub source_ref: SelfStorageRootRef<'a, A>,
261-
pub key: DynamicKey<A>,
227+
pub key: StorageKey<A>,
262228
}
263229

264230
impl<'a, A> StoragePath<A> for SelfStorageRef<'a, A>
@@ -311,7 +277,7 @@ where
311277
A: ManagedTypeApi + ErrorApi + 'static,
312278
{
313279
pub source_ref: SelfStorageRootRefMut<'a, A>,
314-
pub key: DynamicKey<A>,
280+
pub key: StorageKey<A>,
315281
}
316282

317283
impl<'a, A> StoragePath<A> for SelfStorageRefMut<'a, A>
@@ -403,7 +369,7 @@ pub fn _path_lifetimes<A>(root: SelfStorageRootRefMut<'_, A>)
403369
where
404370
A: StorageWriteApi + StorageReadApi + ManagedTypeApi + ErrorApi + 'static,
405371
{
406-
let mut path1 = root.root_path(&DynamicKey(StorageKey::new(b"root")));
372+
let mut path1 = root.root_path(&StorageKey::new(b"root"));
407373
let _path1a = path1.as_ref_mut().concat_key(StrKey("key1a"));
408374
// let path1b = path1.into_ref_mut().concat_key("key1a".to_owned());
409375
// let path1a = path1.concat_key("key1a".to_owned());

0 commit comments

Comments
 (0)