Skip to content
Merged
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
55 changes: 27 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "loro_py"
version = "1.5.4"
version = "1.6.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -10,7 +10,7 @@ crate-type = ["cdylib"]

[dependencies]
# loro = { path = "../loro/crates/loro", features = ["counter", "jsonpath"] }
loro = { version = "1.5.11", features = ["counter", "jsonpath"] }
loro = { version = "1.6.0", features = ["counter", "jsonpath"] }
fxhash = "0.2.1"
pyo3 = { version = "0.25.1" }
pyo3 = { version = "0.26.0" }
serde_json = "1"
11 changes: 7 additions & 4 deletions src/awareness.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(deprecated)]
use std::{borrow::Cow, collections::HashMap};

use loro::{awareness::EphemeralEventTrigger, PeerID};
use loro::{awareness::EphemeralEventTrigger, LoroError, PeerID};
use pyo3::{prelude::*, types::PyBytes};

use crate::{event::Subscription, value::LoroValue};
use crate::{err::PyLoroResult, event::Subscription, value::LoroValue};

pub fn register_class(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Awareness>()?;
Expand Down Expand Up @@ -105,8 +105,11 @@ impl EphemeralStore {
self.0.encode_all()
}

pub fn apply(&mut self, data: &[u8]) {
self.0.apply(data);
pub fn apply(&mut self, data: &[u8]) -> PyLoroResult<()> {
self.0
.apply(data)
.map_err(|e| LoroError::DecodeError(e.into()))?;
Ok(())
}

pub fn set(&mut self, key: &str, value: LoroValue) {
Expand Down
8 changes: 4 additions & 4 deletions src/container/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ impl LoroCounter {
}

/// Increment the counter by the given value.
pub fn increment(&self, py: Python, value: PyObject) -> PyLoroResult<()> {
pub fn increment(&self, py: Python, value: Py<PyAny>) -> PyLoroResult<()> {
self.0.increment(value.extract::<f64>(py)?)?;
Ok(())
}

/// Decrement the counter by the given value.
pub fn decrement(&self, py: Python, value: PyObject) -> PyLoroResult<()> {
pub fn decrement(&self, py: Python, value: Py<PyAny>) -> PyLoroResult<()> {
self.0.decrement(value.extract::<f64>(py)?)?;
Ok(())
}
Expand All @@ -61,9 +61,9 @@ impl LoroCounter {
/// - `doc.export(mode)` is called.
/// - `doc.import(data)` is called.
/// - `doc.checkout(version)` is called.
pub fn subscribe(&self, callback: PyObject) -> Option<Subscription> {
pub fn subscribe(&self, callback: Py<PyAny>) -> Option<Subscription> {
let subscription = self.0.subscribe(Arc::new(move |e| {
Python::with_gil(|py| {
Python::attach(|py| {
callback.call1(py, (DiffEvent::from(e),)).unwrap();
});
}));
Expand Down
8 changes: 4 additions & 4 deletions src/container/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl LoroList {
}

/// Iterate over the elements of the list.
pub fn for_each(&self, f: PyObject) {
Python::with_gil(|py| {
pub fn for_each(&self, f: Py<PyAny>) {
Python::attach(|py| {
self.0.for_each(&mut |v| {
f.call1(py, (ValueOrContainer::from(v),)).unwrap();
});
Expand Down Expand Up @@ -227,9 +227,9 @@ impl LoroList {
/// - `doc.export(mode)` is called.
/// - `doc.import(data)` is called.
/// - `doc.checkout(version)` is called.
pub fn subscribe(&self, callback: PyObject) -> Option<Subscription> {
pub fn subscribe(&self, callback: Py<PyAny>) -> Option<Subscription> {
let subscription = self.0.subscribe(Arc::new(move |e| {
Python::with_gil(|py| {
Python::attach(|py| {
callback.call1(py, (DiffEvent::from(e),)).unwrap();
});
}));
Expand Down
8 changes: 4 additions & 4 deletions src/container/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl LoroMap {

/// Iterate over the key-value pairs of the map.
// TODO: why valueOrHandler?
pub fn for_each(&self, f: PyObject) {
Python::with_gil(|py| {
pub fn for_each(&self, f: Py<PyAny>) {
Python::attach(|py| {
self.0.for_each(move |key, value| {
f.call1(py, (key, ValueOrContainer::from(value))).unwrap();
})
Expand Down Expand Up @@ -159,9 +159,9 @@ impl LoroMap {
/// - `doc.export(mode)` is called.
/// - `doc.import(data)` is called.
/// - `doc.checkout(version)` is called.
pub fn subscribe(&self, callback: PyObject) -> Option<Subscription> {
pub fn subscribe(&self, callback: Py<PyAny>) -> Option<Subscription> {
let subscription = self.0.subscribe(Arc::new(move |e| {
Python::with_gil(|py| {
Python::attach(|py| {
callback.call1(py, (DiffEvent::from(e),)).unwrap();
});
}));
Expand Down
8 changes: 4 additions & 4 deletions src/container/movable_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ impl LoroMovableList {
}

/// Iterate over the elements of the list.
pub fn for_each(&self, f: PyObject) {
Python::with_gil(|py| {
pub fn for_each(&self, f: Py<PyAny>) {
Python::attach(|py| {
self.0.for_each(&mut |v| {
f.call1(py, (ValueOrContainer::from(v),)).unwrap();
});
Expand Down Expand Up @@ -237,9 +237,9 @@ impl LoroMovableList {
/// - `doc.export(mode)` is called.
/// - `doc.import(data)` is called.
/// - `doc.checkout(version)` is called.
pub fn subscribe(&self, callback: PyObject) -> Option<Subscription> {
pub fn subscribe(&self, callback: Py<PyAny>) -> Option<Subscription> {
let subscription = self.0.subscribe(Arc::new(move |e| {
Python::with_gil(|py| {
Python::attach(|py| {
callback.call1(py, (DiffEvent::from(e),)).unwrap();
});
}));
Expand Down
4 changes: 2 additions & 2 deletions src/container/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ impl LoroText {
/// - `doc.export(mode)` is called.
/// - `doc.import(data)` is called.
/// - `doc.checkout(version)` is called.
pub fn subscribe(&self, callback: PyObject) -> Option<Subscription> {
pub fn subscribe(&self, callback: Py<PyAny>) -> Option<Subscription> {
let subscription = self.0.subscribe(Arc::new(move |e| {
Python::with_gil(|py| {
Python::attach(|py| {
callback.call1(py, (DiffEvent::from(e),)).unwrap();
});
}));
Expand Down
4 changes: 2 additions & 2 deletions src/container/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ impl LoroTree {
/// - `doc.export(mode)` is called.
/// - `doc.import(data)` is called.
/// - `doc.checkout(version)` is called.
pub fn subscribe(&self, callback: PyObject) -> Option<Subscription> {
pub fn subscribe(&self, callback: Py<PyAny>) -> Option<Subscription> {
let subscription = self.0.subscribe(Arc::new(move |e| {
Python::with_gil(|py| {
Python::attach(|py| {
callback.call1(py, (DiffEvent::from(e),)).unwrap();
});
}));
Expand Down
Loading