Move the StorageEntity method types into the StorageEntity trait itself so that you don't need to implement for all types

This commit is contained in:
Andrew Morris
2023-10-31 12:55:56 +11:00
parent 00776c212c
commit 44802a1843
6 changed files with 28 additions and 44 deletions

View File

@@ -45,11 +45,8 @@ impl DecoderMaker for Rc<Bytecode> {
}
}
impl StorageEntity for Bytecode {
fn to_storage_entry<'a, E, Tx: StorageBackendHandle<'a, E>>(
&self,
_tx: &mut Tx,
) -> Result<storage::StorageEntry, E> {
impl<'a, E, Tx: StorageBackendHandle<'a, E>> StorageEntity<'a, E, Tx> for Bytecode {
fn to_storage_entry(&self, _tx: &mut Tx) -> Result<storage::StorageEntry, E> {
Ok(storage::StorageEntry {
ref_count: 1,
refs: vec![],
@@ -57,10 +54,7 @@ impl StorageEntity for Bytecode {
})
}
fn from_storage_entry<'a, E, Tx: StorageBackendHandle<'a, E>>(
_tx: &mut Tx,
entry: storage::StorageEntry,
) -> Result<Self, E> {
fn from_storage_entry(_tx: &mut Tx, entry: storage::StorageEntry) -> Result<Self, E> {
Ok(Bytecode::new(entry.data))
}
}

View File

@@ -47,11 +47,8 @@ impl Tag {
}
}
impl StorageEntity for Val {
fn from_storage_entry<'a, E, Tx: StorageBackendHandle<'a, E>>(
tx: &mut Tx,
entry: StorageEntry,
) -> Result<Self, E> {
impl<'a, E, Tx: StorageBackendHandle<'a, E>> StorageEntity<'a, E, Tx> for Val {
fn from_storage_entry(tx: &mut Tx, entry: StorageEntry) -> Result<Self, E> {
let mut reader = StorageEntryReader::new(&entry);
let res = read_from_entry(tx, &mut reader);
assert!(reader.done());
@@ -59,10 +56,7 @@ impl StorageEntity for Val {
res
}
fn to_storage_entry<'a, E, Tx: StorageBackendHandle<'a, E>>(
&self,
tx: &mut Tx,
) -> Result<StorageEntry, E> {
fn to_storage_entry(&self, tx: &mut Tx) -> Result<StorageEntry, E> {
let mut entry = StorageEntry {
ref_count: 1,
refs: vec![],