diff --git a/rust/src/automerge.udl b/rust/src/automerge.udl index 620239a..63d12a4 100644 --- a/rust/src/automerge.udl +++ b/rust/src/automerge.udl @@ -112,7 +112,7 @@ dictionary MarkSet { interface AMValue { Map ( record value ); Scalar ( ScalarValue value ); - List ( sequence value ); + List ( sequence value ); Text ( HydratedText value ); }; @@ -121,7 +121,7 @@ dictionary HydratedText { record marks; }; -dictionary HydratedList { +dictionary HydratedListItem { AMValue value; record marks; boolean conflict; diff --git a/rust/src/doc.rs b/rust/src/doc.rs index 6f4b802..dad8e7b 100644 --- a/rust/src/doc.rs +++ b/rust/src/doc.rs @@ -7,6 +7,7 @@ use automerge::{transaction::Transactable, ReadDoc}; use crate::actor_id::ActorId; use crate::cursor::Position; use crate::mark::{ExpandMark, KeyValue, Mark}; +use crate::span::{Span}; use crate::patches::Patch; use crate::{ Change, ChangeHash, Cursor, ObjId, ObjType, PathElement, ScalarValue, SyncState, Value, @@ -514,6 +515,15 @@ impl Doc { Ok(()) } + pub fn spans(&self, obj: ObjId) -> Result, DocError> { + let mut doc = self.0.write().unwrap(); + let obj = am::ObjId::from(obj); + let x = doc.spans(obj).unwrap(); + let y = x + .into_iter() + .map(am::iter::spans::from); + } + pub fn merge(&self, other: Arc) -> Result<(), DocError> { let mut doc = self.0.write().unwrap(); let mut other = other.0.write().unwrap(); diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 80266aa..ca0ebb4 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -27,4 +27,4 @@ use sync_state::{DecodeSyncStateError, SyncState}; mod value; use value::Value; mod span; -use span::{AMValue, HydratedList, HydratedText, MarkSet, Span}; +use span::{AMValue, HydratedListItem, HydratedText, MarkSet, Span}; diff --git a/rust/src/span.rs b/rust/src/span.rs index 47bf7d9..27357cf 100644 --- a/rust/src/span.rs +++ b/rust/src/span.rs @@ -1,6 +1,6 @@ use crate::ScalarValue; use std::collections::HashMap; -// use automerge as am; +use automerge as am; // maps to am::iter::Span // need to create From<> in to convert over @@ -14,22 +14,57 @@ pub enum Span { Block { value: HashMap }, } +// impl From for am::iter::Spans<'_> { +// fn from(value: Span) -> Self { +// let inner: [u8; 32] = value.0.try_into().unwrap(); +// am::ChangeHash(inner) +// } +// } + +impl<'a> From<&'a am::iter::Span> for Span { + fn from(value: &'a am::iter::Span) -> Self { + match value { + am::iter::Span::Text( t, m) => Self::Text { text: t.to_string(), marks: Option>::from() }, + am::iter::Span::Block( value ) => Self::Block { value: HashMap::from(value) } + } + } +} + +impl<'a> From<&'a am::hydrate::Map> for HashMap { + fn from(value: &'a am::hydrate::Map) -> Self { + let mut new_hash_map:HashMap = HashMap::new(); + // fill in the middle bits... + return new_hash_map; + } +} + // loosely maps to am::marks:MarkSet // need to create From<> in to convert over pub struct MarkSet { pub marks: HashMap, } +impl<'a> From<&'a am::marks::MarkSet> for MarkSet { + fn from(value: &'a am::marks::MarkSet) -> Self { + let mut new_hash:HashMap = HashMap::new(); + // iterate through MarkSet, building a hashmap for this MarkSet + for (k, v) in value.iter() { + new_hash.insert(k.to_string(), v.into()); + } + Self { marks: new_hash } + } +} + pub enum AMValue { Map { value: HashMap }, Scalar { value: ScalarValue }, - List { value: Vec }, + List { value: Vec }, Text { value: HydratedText }, } // loosely maps to am::hydrate::ListValue // need to create From<> in to convert over -pub struct HydratedList { +pub struct HydratedListItem { pub value: AMValue, pub marks: HashMap, pub conflict: bool,