Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 158 additions & 113 deletions rust/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ path = "uniffi-bindgen.rs"
required-features = ["uniffi/cli"]

[dependencies]
automerge = { version = "0.6.1", default-features = false, features = ["wasm"] }
automerge = { version = "1.0.0-beta.3", default-features = false, features = ["wasm"] }
thiserror = "1.0.38"
uniffi = "0.28.2"

Expand Down
2 changes: 1 addition & 1 deletion rust/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl From<am::Change> for Change {
Change {
actor_id: value.actor_id().into(),
message: value.message().cloned(),
deps: value.deps().into_iter().map(ChangeHash::from).collect(),
deps: value.deps().iter().map(ChangeHash::from).collect(),
timestamp: value.timestamp(),
bytes: value.bytes().into_owned(),
hash: value.hash().into(),
Expand Down
20 changes: 14 additions & 6 deletions rust/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,13 @@ impl Doc {
assert_map(&*doc, &obj)?;
Ok(doc
.map_range(&obj, ..)
.map(|am::iter::MapRangeItem { key, value, id, .. }| KeyValue {
key: key.into(),
value: (value, id).into(),
.map(|item| {
let id = item.id();
let value = item.value;
KeyValue {
key: item.key.into(),
value: (value, id).into(),
}
})
.collect::<Vec<_>>())
}
Expand All @@ -294,9 +298,13 @@ impl Doc {
assert_map(&*doc, &obj)?;
Ok(doc
.map_range_at(&obj, .., &heads)
.map(|am::iter::MapRangeItem { key, value, id, .. }| KeyValue {
key: key.into(),
value: (value, id).into(),
.map(|item| {
let id = item.id();
let value = item.value;
KeyValue {
key: item.key.into(),
value: (value, id).into(),
}
})
.collect::<Vec<_>>())
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub struct Mark {
pub value: ScalarValue,
}

impl<'a> From<&'a am::marks::Mark<'a>> for Mark {
fn from(am_mark: &'a am::marks::Mark<'a>) -> Mark {
impl From<&am::marks::Mark> for Mark {
fn from(am_mark: &am::marks::Mark) -> Mark {
Mark {
start: am_mark.start as u64,
end: am_mark.end as u64,
Expand Down
45 changes: 45 additions & 0 deletions rust/src/scalar_value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use automerge as am;
use automerge::ScalarValueRef;

pub enum ScalarValue {
Bytes { value: Vec<u8> },
Expand Down Expand Up @@ -54,3 +55,47 @@ impl<'a> From<&'a am::ScalarValue> for ScalarValue {
}
}
}

impl From<am::ScalarValue> for ScalarValue {
fn from(value: am::ScalarValue) -> Self {
match value {
am::ScalarValue::Bytes(b) => ScalarValue::Bytes { value: b },
am::ScalarValue::Str(s) => ScalarValue::String {
value: s.to_string(),
},
am::ScalarValue::Int(n) => ScalarValue::Int { value: n },
am::ScalarValue::Uint(n) => ScalarValue::Uint { value: n },
am::ScalarValue::F64(n) => ScalarValue::F64 { value: n },
am::ScalarValue::Counter(c) => ScalarValue::Counter { value: c.into() },
am::ScalarValue::Timestamp(n) => ScalarValue::Timestamp { value: n },
am::ScalarValue::Boolean(b) => ScalarValue::Boolean { value: b },
am::ScalarValue::Unknown { type_code, bytes } => ScalarValue::Unknown {
type_code,
data: bytes,
},
am::ScalarValue::Null => ScalarValue::Null,
}
}
}

impl<'a> From<&ScalarValueRef<'a>> for ScalarValue {
fn from(value: &ScalarValueRef<'a>) -> Self {
match value {
ScalarValueRef::Bytes(b) => ScalarValue::Bytes { value: b.to_vec() },
ScalarValueRef::Str(s) => ScalarValue::String {
value: s.to_string(),
},
ScalarValueRef::Int(n) => ScalarValue::Int { value: *n },
ScalarValueRef::Uint(n) => ScalarValue::Uint { value: *n },
ScalarValueRef::F64(n) => ScalarValue::F64 { value: *n },
ScalarValueRef::Counter(c) => ScalarValue::Counter { value: *c },
ScalarValueRef::Timestamp(n) => ScalarValue::Timestamp { value: *n },
ScalarValueRef::Boolean(b) => ScalarValue::Boolean { value: *b },
ScalarValueRef::Null => ScalarValue::Null,
ScalarValueRef::Unknown { type_code, bytes } => ScalarValue::Unknown {
type_code: *type_code,
data: bytes.to_vec(),
},
}
}
}
12 changes: 12 additions & 0 deletions rust/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ impl<'a> From<(am::Value<'a>, am::ObjId)> for Value {
}
}
}

impl<'a> From<(am::ValueRef<'a>, am::ObjId)> for Value {
fn from(value: (am::ValueRef<'a>, am::ObjId)) -> Self {
match value {
(am::ValueRef::Object(ty), id) => Value::Object {
typ: ObjType::from(ty),
id: id.into(),
},
(am::ValueRef::Scalar(s), _) => Value::Scalar { value: (&s).into() },
}
}
}
2 changes: 1 addition & 1 deletion scripts/build-xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ XCFRAMEWORK_FOLDER="$THIS_SCRIPT_DIR/../${FRAMEWORK_NAME}.xcframework"
# (as of 10/10/23), but leaving it open to float seems less useful than
# moving the pinning forward, since Catalyst support (target macabi) still
# requires an active, nightly toolchain.
RUST_NIGHTLY="nightly-2024-05-23"
RUST_NIGHTLY="nightly-2024-12-01"

echo "Install nightly and rust-src for Catalyst"
rustup toolchain install ${RUST_NIGHTLY}
Expand Down