instance and item now use dynamic dispatch
This commit is contained in:
@@ -5,6 +5,7 @@ use sysinfo::{System, Pid, ProcessRefreshKind, RefreshKind};
|
||||
use std::io::Write;
|
||||
use ciborium::Value as CborValue;
|
||||
|
||||
use crate::instance::store::IdIter;
|
||||
use crate::item::IntoItemData;
|
||||
use crate::memstore::MemStore;
|
||||
use crate::{core::instance::store::Store, mize_err};
|
||||
@@ -57,17 +58,17 @@ impl Store for FileStore {
|
||||
return Ok(id_string);
|
||||
}
|
||||
|
||||
fn set<T: Into<ItemData>>(&self, id: MizeId, data: T) -> MizeResult<()> {
|
||||
fn set(&self, id: MizeId, data: ItemData) -> MizeResult<()> {
|
||||
let file = OpenOptions::new().write(true).create(true).open(self.path.join("store").join(id.store_part()))?;
|
||||
ciborium::into_writer(data.into().cbor(), file)?;
|
||||
ciborium::into_writer(data.cbor(), file)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_links(&self, item: Item<Self>) -> MizeResult<Vec<MizeId>> {
|
||||
fn get_links(&self, item: Item) -> MizeResult<Vec<MizeId>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn get_backlinks(&self, item: Item<Self>) -> MizeResult<Vec<MizeId>> {
|
||||
fn get_backlinks(&self, item: Item) -> MizeResult<Vec<MizeId>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
@@ -100,8 +101,14 @@ impl Store for FileStore {
|
||||
|
||||
return Ok(ret_data);
|
||||
}
|
||||
fn id_iter(&self) -> MizeResult<impl Iterator<Item=String> + '_> {
|
||||
Ok(vec!["1".to_owned(), "2".to_owned()].into_iter())
|
||||
fn id_iter(&self) -> MizeResult<IdIter> {
|
||||
todo!()
|
||||
}
|
||||
fn next_id(&self, prev_id: &str) -> MizeResult<Option<String>> {
|
||||
todo!()
|
||||
}
|
||||
fn first_id(&self) -> MizeResult<String> {
|
||||
Ok("0".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ mod fsstore;
|
||||
//mod unix-socket;
|
||||
|
||||
|
||||
pub fn os_instance_init<S: Store>(instance: Instance<MemStore>) -> MizeResult<Instance<FileStore>> {
|
||||
pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> {
|
||||
// this is the code, that runs to initialize an Instance on a system with an os present.
|
||||
|
||||
////// load MIZE_CONFIG_FILE as the instance, which is item 0
|
||||
@@ -63,8 +63,8 @@ pub fn os_instance_init<S: Store>(instance: Instance<MemStore>) -> MizeResult<In
|
||||
|
||||
if store_path != "" {
|
||||
let file_store = FileStore::new(store_path)?;
|
||||
let new_instance = &mut instance.migrate_to_store(file_store)?;
|
||||
return Ok(new_instance);
|
||||
let new_instance = &mut instance.migrate_to_store(Box::new(file_store))?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
||||
Reference in New Issue
Block a user