instance and item now use dynamic dispatch
This commit is contained in:
@@ -15,14 +15,14 @@ pub trait Store {
|
||||
// is implemented, so that there can be a multithreaded implementation
|
||||
//fn get(self, id: MizeId) -> MizeResult<Item<Self>> where Self: Sized;
|
||||
|
||||
fn set<T: Into<ItemData>>(&self, id: MizeId, data: T) -> MizeResult<()>;
|
||||
fn set(&self, id: MizeId, data: ItemData) -> MizeResult<()>;
|
||||
|
||||
// in the future should implement transactions, ....
|
||||
|
||||
// funcs to do with links, backlinks
|
||||
fn get_links(&self, item: Item<Self>) -> MizeResult<Vec<MizeId>> where Self: Sized;
|
||||
fn get_links(&self, item: Item) -> MizeResult<Vec<MizeId>>;
|
||||
|
||||
fn get_backlinks(&self, item: Item<Self>) -> MizeResult<Vec<MizeId>> where Self: Sized;
|
||||
fn get_backlinks(&self, item: Item) -> MizeResult<Vec<MizeId>>;
|
||||
|
||||
fn new_id(&self) -> MizeResult<String>;
|
||||
|
||||
@@ -30,6 +30,40 @@ pub trait Store {
|
||||
|
||||
fn get_value_data_full(&self, id: MizeId) -> MizeResult<ItemData>;
|
||||
|
||||
fn id_iter(&self) -> MizeResult<impl Iterator<Item=String> + '_>;
|
||||
fn id_iter(&self) -> MizeResult<IdIter>;
|
||||
|
||||
fn next_id(&self, prev_id: &str) -> MizeResult<Option<String>>;
|
||||
|
||||
fn first_id(&self) -> MizeResult<String>;
|
||||
}
|
||||
|
||||
pub struct IdIter {
|
||||
cur_id: String,
|
||||
store: Box<dyn Store>,
|
||||
}
|
||||
|
||||
impl IdIter {
|
||||
pub fn new(store: Box<dyn Store>) -> MizeResult<IdIter> {
|
||||
Ok(IdIter { cur_id: store.first_id()?, store })
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for IdIter {
|
||||
type Item = MizeResult<String>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.store.next_id(&self.cur_id) {
|
||||
Err(err) => {
|
||||
Some(Err(err))
|
||||
},
|
||||
Ok(Some(new_id)) => {
|
||||
self.cur_id = new_id.clone();
|
||||
Some(Ok(new_id))
|
||||
},
|
||||
Ok(None) => {
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user