mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-05-10 03:00:06 -04:00
Split out storage_entry
This commit is contained in:
@@ -5,6 +5,7 @@ mod rc_key;
|
||||
mod serde_rc;
|
||||
mod sled_backend;
|
||||
mod storage_backend;
|
||||
mod storage_entry;
|
||||
mod storage_ops;
|
||||
mod storage_ptr;
|
||||
mod storage_val;
|
||||
|
||||
37
storage/src/storage_entry.rs
Normal file
37
storage/src/storage_entry.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
storage_ptr::StorageEntryPtr,
|
||||
storage_val::{StorageCompoundVal, StorageVal},
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct StorageEntry {
|
||||
pub(crate) ref_count: u64,
|
||||
pub(crate) refs: Vec<StorageEntryPtr>,
|
||||
pub(crate) data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl StorageEntry {
|
||||
pub fn move_to_val(self) -> StorageVal {
|
||||
let Self {
|
||||
ref_count: _,
|
||||
refs,
|
||||
data,
|
||||
} = self;
|
||||
|
||||
let mut val = bincode::deserialize::<StorageVal>(&data).unwrap();
|
||||
|
||||
if let StorageVal::Compound(compound) = &mut val {
|
||||
match Rc::get_mut(compound).expect("Should be single ref") {
|
||||
StorageCompoundVal::Array(arr) => {
|
||||
arr.refs = refs;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
val
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ use std::hash::Hash;
|
||||
|
||||
use rand::{rngs::ThreadRng, Rng};
|
||||
|
||||
use crate::storage_val::StorageEntry;
|
||||
use crate::storage_entry::StorageEntry;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Hash, PartialEq, Eq)]
|
||||
pub struct StoragePtr<T> {
|
||||
|
||||
@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::rc_key::RcKey;
|
||||
use crate::serde_rc::{deserialize_rc, serialize_rc};
|
||||
use crate::storage_entry::StorageEntry;
|
||||
use crate::storage_ops::StorageOps;
|
||||
use crate::storage_ptr::StorageEntryPtr;
|
||||
|
||||
@@ -189,36 +190,6 @@ impl StorageVal {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct StorageEntry {
|
||||
pub(crate) ref_count: u64,
|
||||
pub(crate) refs: Vec<StorageEntryPtr>,
|
||||
|
||||
data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl StorageEntry {
|
||||
pub fn move_to_val(self) -> StorageVal {
|
||||
let Self {
|
||||
ref_count: _,
|
||||
refs,
|
||||
data,
|
||||
} = self;
|
||||
|
||||
let mut val = bincode::deserialize::<StorageVal>(&data).unwrap();
|
||||
|
||||
if let StorageVal::Compound(compound) = &mut val {
|
||||
match Rc::get_mut(compound).expect("Should be single ref") {
|
||||
StorageCompoundVal::Array(arr) => {
|
||||
arr.refs = refs;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
fn cache_and_store<E, SO: StorageOps<E>>(
|
||||
tx: &mut SO,
|
||||
val: &StorageVal,
|
||||
|
||||
Reference in New Issue
Block a user