From a0635c7536362dff2b3162551b7797070157a06c Mon Sep 17 00:00:00 2001 From: Leon Zhao Date: Sun, 31 Aug 2025 13:45:24 +0800 Subject: [PATCH] chore: bump loro 1.6.0 and pyo3 0.26 --- Cargo.lock | 55 +++++++++++++++++------------------ Cargo.toml | 6 ++-- src/awareness.rs | 11 ++++--- src/container/counter.rs | 8 ++--- src/container/list.rs | 8 ++--- src/container/map.rs | 8 ++--- src/container/movable_list.rs | 8 ++--- src/container/text.rs | 4 +-- src/container/tree.rs | 4 +-- src/doc.rs | 28 +++++++++--------- src/undo.rs | 8 ++--- 11 files changed, 75 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1870c34..025ed1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -462,9 +462,9 @@ dependencies = [ [[package]] name = "loro" -version = "1.5.11" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a95643130841a4deab62ad4b7d782d0bac71688480f4efade6d13d9c5ca741d2" +checksum = "7e9ca0d5904636a1eb8400245a61f61646e66f06820735039f96987d71050f4d" dependencies = [ "enum-as-inner 0.6.1", "fxhash", @@ -478,9 +478,9 @@ dependencies = [ [[package]] name = "loro-common" -version = "1.5.10" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b0b2739af1bc260f0a7d7cf072bf7d28c584ff021c0bc28b2a911b4822543b" +checksum = "e6786df19193f53407bc9ba34446a39c520aaa5224d2ed1d648bac39dd1afb21" dependencies = [ "arbitrary", "enum-as-inner 0.6.1", @@ -496,9 +496,9 @@ dependencies = [ [[package]] name = "loro-delta" -version = "1.5.6" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9b920ad564430b2e392ac6f0e8f97ef5745960cc40edc482be57a407db1c243" +checksum = "c28890ffa0aff47ec5311aa1f55a6c3dfd39bbcac9dc8996106b7882e8fb1d26" dependencies = [ "arrayvec", "enum-as-inner 0.5.1", @@ -508,9 +508,9 @@ dependencies = [ [[package]] name = "loro-internal" -version = "1.5.10" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e016320208e96cc20ed01a050a2fea10fc71760fde7a7670a673d6af4b7905" +checksum = "7947d2db10f3a90b5a5d713f47710ef0f105b27c973fd4108b25bd22d4f2ad2a" dependencies = [ "append-only-bytes", "arref", @@ -552,9 +552,9 @@ dependencies = [ [[package]] name = "loro-kv-store" -version = "1.5.10" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54a5e9e9c3cb13e162835c1e94cf6b9df691b6e1bbc456f4cdc0471968adc82" +checksum = "e5c96c47a94a684d876bb4ab6e930bfd0f0ff7230c4c601ff07a8900c9af2eee" dependencies = [ "bytes", "ensure-cov", @@ -569,9 +569,9 @@ dependencies = [ [[package]] name = "loro-rle" -version = "1.2.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077b51e4eac04e7f18574f7e6ac0201ffd98ff65015343eee3702bc3e7c49dc8" +checksum = "76400c3eea6bb39b013406acce964a8db39311534e308286c8d8721baba8ee20" dependencies = [ "append-only-bytes", "num", @@ -586,9 +586,9 @@ checksum = "3f3d053a135388e6b1df14e8af1212af5064746e9b87a06a345a7a779ee9695a" [[package]] name = "loro_fractional_index" -version = "1.2.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e387a04d7d6a74ebb3434c906c84ddcae4413e5ef8bcd8e7d5138959d416a512" +checksum = "427c8ea186958094052b971fe7e322a934b034c3bf62f0458ccea04fcd687ba1" dependencies = [ "once_cell", "rand", @@ -597,7 +597,7 @@ dependencies = [ [[package]] name = "loro_py" -version = "1.5.4" +version = "1.6.0" dependencies = [ "fxhash", "loro", @@ -735,9 +735,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.2" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "overload" @@ -823,9 +823,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.25.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8970a78afe0628a3e3430376fc5fd76b6b45c4d43360ffd6cdd40bdde72b682a" +checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383" dependencies = [ "indoc", "libc", @@ -840,19 +840,18 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.25.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458eb0c55e7ece017adeba38f2248ff3ac615e53660d7c71a238d7d2a01c7598" +checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f" dependencies = [ - "once_cell", "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.25.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7114fe5457c61b276ab77c5055f206295b812608083644a5c5b2640c3102565c" +checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105" dependencies = [ "libc", "pyo3-build-config", @@ -860,9 +859,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.25.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8725c0a622b374d6cb051d11a0983786448f7785336139c3c94f5aa6bef7e50" +checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -872,9 +871,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.25.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4109984c22491085343c05b0dbc54ddc405c3cf7b4374fc533f5c3313a572ccc" +checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf" dependencies = [ "heck 0.5.0", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index bff124f..49c18c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 @@ -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" diff --git a/src/awareness.rs b/src/awareness.rs index 49259e0..3a84cb1 100644 --- a/src/awareness.rs +++ b/src/awareness.rs @@ -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::()?; @@ -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) { diff --git a/src/container/counter.rs b/src/container/counter.rs index f894780..7620657 100644 --- a/src/container/counter.rs +++ b/src/container/counter.rs @@ -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) -> PyLoroResult<()> { self.0.increment(value.extract::(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) -> PyLoroResult<()> { self.0.decrement(value.extract::(py)?)?; Ok(()) } @@ -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 { + pub fn subscribe(&self, callback: Py) -> Option { let subscription = self.0.subscribe(Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); })); diff --git a/src/container/list.rs b/src/container/list.rs index 1677c0a..76246a3 100644 --- a/src/container/list.rs +++ b/src/container/list.rs @@ -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) { + Python::attach(|py| { self.0.for_each(&mut |v| { f.call1(py, (ValueOrContainer::from(v),)).unwrap(); }); @@ -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 { + pub fn subscribe(&self, callback: Py) -> Option { let subscription = self.0.subscribe(Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); })); diff --git a/src/container/map.rs b/src/container/map.rs index b9f7aa2..d41d5f4 100644 --- a/src/container/map.rs +++ b/src/container/map.rs @@ -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) { + Python::attach(|py| { self.0.for_each(move |key, value| { f.call1(py, (key, ValueOrContainer::from(value))).unwrap(); }) @@ -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 { + pub fn subscribe(&self, callback: Py) -> Option { let subscription = self.0.subscribe(Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); })); diff --git a/src/container/movable_list.rs b/src/container/movable_list.rs index 81baf14..b385d95 100644 --- a/src/container/movable_list.rs +++ b/src/container/movable_list.rs @@ -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) { + Python::attach(|py| { self.0.for_each(&mut |v| { f.call1(py, (ValueOrContainer::from(v),)).unwrap(); }); @@ -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 { + pub fn subscribe(&self, callback: Py) -> Option { let subscription = self.0.subscribe(Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); })); diff --git a/src/container/text.rs b/src/container/text.rs index d27f325..cb96b5b 100644 --- a/src/container/text.rs +++ b/src/container/text.rs @@ -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 { + pub fn subscribe(&self, callback: Py) -> Option { let subscription = self.0.subscribe(Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); })); diff --git a/src/container/tree.rs b/src/container/tree.rs index e21e29b..3b7c0db 100644 --- a/src/container/tree.rs +++ b/src/container/tree.rs @@ -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 { + pub fn subscribe(&self, callback: Py) -> Option { let subscription = self.0.subscribe(Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); })); diff --git a/src/doc.rs b/src/doc.rs index 4131ce6..7c764b5 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -659,11 +659,11 @@ impl LoroDoc { /// sub.unsubscribe(); /// ``` #[inline] - pub fn subscribe(&self, container_id: &ContainerID, callback: PyObject) -> Subscription { + pub fn subscribe(&self, container_id: &ContainerID, callback: Py) -> Subscription { let subscription = self.doc.subscribe( &container_id.into(), Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); }), @@ -683,9 +683,9 @@ impl LoroDoc { /// - `doc.import(data)` is called. /// - `doc.checkout(version)` is called. #[inline] - pub fn subscribe_root(&self, callback: PyObject) -> Subscription { + pub fn subscribe_root(&self, callback: Py) -> Subscription { let subscription = self.doc.subscribe_root(Arc::new(move |e| { - Python::with_gil(|py| { + Python::attach(|py| { callback.call1(py, (DiffEvent::from(e),)).unwrap(); }); })); @@ -693,9 +693,9 @@ impl LoroDoc { } /// Subscribe the local update of the document. - pub fn subscribe_local_update(&self, callback: PyObject) -> Subscription { + pub fn subscribe_local_update(&self, callback: Py) -> Subscription { let subscription = self.doc.subscribe_local_update(Box::new(move |updates| { - Python::with_gil(|py| { + Python::attach(|py| { let b = callback.call1(py, (updates,)).unwrap(); b.extract::(py).unwrap() }) @@ -704,9 +704,9 @@ impl LoroDoc { } /// Subscribe the peer id change of the document. - pub fn subscribe_peer_id_change(&self, callback: PyObject) -> Subscription { + pub fn subscribe_peer_id_change(&self, callback: Py) -> Subscription { let subscription = self.doc.subscribe_peer_id_change(Box::new(move |id| { - Python::with_gil(|py| { + Python::attach(|py| { let b = callback.call1(py, (ID::from(*id),)).unwrap(); b.extract::(py).unwrap() }) @@ -879,11 +879,11 @@ impl LoroDoc { /// /// * `ids` - The IDs of the Change to start the traversal from. /// * `cb` - A callback function that is called for each ancestor. It can return `True` to stop the traversal. - pub fn travel_change_ancestors(&self, ids: Vec, cb: PyObject) -> PyLoroResult<()> { + pub fn travel_change_ancestors(&self, ids: Vec, cb: Py) -> PyLoroResult<()> { self.doc.travel_change_ancestors( &ids.into_iter().map(|id| id.into()).collect::>(), &mut |meta| { - let b = Python::with_gil(|py| { + let b = Python::attach(|py| { cb.call1(py, (ChangeMeta::from(meta),)) .unwrap() .extract::(py) @@ -970,11 +970,11 @@ impl LoroDoc { /// /// This is useful for managing the relationship between `PeerID` and user information. /// For example, you could store user names in a `LoroMap` using `PeerID` as the key and the `UserID` as the value. - pub fn subscribe_first_commit_from_peer(&self, callback: PyObject) -> Subscription { + pub fn subscribe_first_commit_from_peer(&self, callback: Py) -> Subscription { let subscription = self .doc .subscribe_first_commit_from_peer(Box::new(move |payload| { - Python::with_gil(|py| { + Python::attach(|py| { let b = callback .call1(py, (FirstCommitFromPeerPayload { peer: payload.peer },)) .unwrap(); @@ -988,9 +988,9 @@ impl LoroDoc { /// /// The callback will be called when the changes are committed but not yet applied to the OpLog. /// You can modify the commit message and timestamp in the callback by [`ChangeModifier`]. - pub fn subscribe_pre_commit(&self, callback: PyObject) -> Subscription { + pub fn subscribe_pre_commit(&self, callback: Py) -> Subscription { let subscription = self.doc.subscribe_pre_commit(Box::new(move |payload| { - Python::with_gil(|py| { + Python::attach(|py| { let b = callback .call1( py, diff --git a/src/undo.rs b/src/undo.rs index cf4857b..68d6c31 100644 --- a/src/undo.rs +++ b/src/undo.rs @@ -78,10 +78,10 @@ impl UndoManager { /// Set the listener for push events. /// The listener will be called when a new undo/redo item is pushed into the stack. - pub fn set_on_push(&mut self, on_push: PyObject) { + pub fn set_on_push(&mut self, on_push: Py) { self.0 .set_on_push(Some(Box::new(move |undo_or_redo, span, event| { - Python::with_gil(|py| { + Python::attach(|py| { let meta = on_push .call1( py, @@ -101,10 +101,10 @@ impl UndoManager { /// Set the listener for pop events. /// The listener will be called when an undo/redo item is popped from the stack. - pub fn set_on_pop(&mut self, on_pop: PyObject) { + pub fn set_on_pop(&mut self, on_pop: Py) { self.0 .set_on_pop(Some(Box::new(move |undo_or_redo, span, meta| { - Python::with_gil(|py| { + Python::attach(|py| { on_pop .call1( py,