automerge 0.2.0

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically
Documentation
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
        }
    }
}