After some discussion with PVH I realise that the repo structure in the last reorg was very rust-centric. In an attempt to put each language on a level footing move the rust code and project files into ./rust
35 lines
809 B
Rust
35 lines
809 B
Rust
use crate::op_set::OpSet;
|
|
use crate::types::ObjId;
|
|
use crate::{exid::ExId, Prop};
|
|
|
|
#[derive(Debug)]
|
|
pub struct Parents<'a> {
|
|
pub(crate) obj: ObjId,
|
|
pub(crate) ops: &'a OpSet,
|
|
}
|
|
|
|
impl<'a> Parents<'a> {
|
|
pub fn path(&mut self) -> Vec<(ExId, Prop)> {
|
|
let mut path = self.collect::<Vec<_>>();
|
|
path.reverse();
|
|
path
|
|
}
|
|
}
|
|
|
|
impl<'a> Iterator for Parents<'a> {
|
|
type Item = (ExId, Prop);
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
if self.obj.is_root() {
|
|
None
|
|
} else if let Some((obj, key)) = self.ops.parent_object(&self.obj) {
|
|
self.obj = obj;
|
|
Some((
|
|
self.ops.id_to_exid(self.obj.0),
|
|
self.ops.export_key(self.obj, key),
|
|
))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|