mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-05 12:14:43 +00:00
feat(ffi): add get_attached (#621)
This commit is contained in:
parent
2df24725df
commit
a1e81eece0
6 changed files with 53 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use loro::{ContainerTrait, LoroResult};
|
||||
|
||||
use crate::ContainerID;
|
||||
|
@ -14,6 +16,21 @@ impl LoroCounter {
|
|||
}
|
||||
}
|
||||
|
||||
/// Whether the container is attached to a document
|
||||
///
|
||||
/// The edits on a detached container will not be persisted.
|
||||
/// To attach the container to the document, please insert it into an attached container.
|
||||
pub fn is_attached(&self) -> bool {
|
||||
self.counter.is_attached()
|
||||
}
|
||||
|
||||
/// If a detached container is attached, this method will return its corresponding attached handler.
|
||||
pub fn get_attached(&self) -> Option<Arc<LoroCounter>> {
|
||||
self.counter
|
||||
.get_attached()
|
||||
.map(|x| Arc::new(LoroCounter { counter: x }))
|
||||
}
|
||||
|
||||
/// Return container id of the Counter.
|
||||
pub fn id(&self) -> ContainerID {
|
||||
self.counter.id().into()
|
||||
|
|
|
@ -26,6 +26,13 @@ impl LoroList {
|
|||
self.list.is_attached()
|
||||
}
|
||||
|
||||
/// If a detached container is attached, this method will return its corresponding attached handler.
|
||||
pub fn get_attached(&self) -> Option<Arc<LoroList>> {
|
||||
self.list
|
||||
.get_attached()
|
||||
.map(|x| Arc::new(LoroList { list: x }))
|
||||
}
|
||||
|
||||
/// Insert a value at the given position.
|
||||
pub fn insert(&self, pos: u32, v: Arc<dyn LoroValueLike>) -> LoroResult<()> {
|
||||
self.list.insert(pos as usize, v.as_loro_value())
|
||||
|
|
|
@ -22,6 +22,13 @@ impl LoroMap {
|
|||
self.map.is_attached()
|
||||
}
|
||||
|
||||
/// If a detached container is attached, this method will return its corresponding attached handler.
|
||||
pub fn get_attached(&self) -> Option<Arc<LoroMap>> {
|
||||
self.map
|
||||
.get_attached()
|
||||
.map(|x| Arc::new(LoroMap { map: x }))
|
||||
}
|
||||
|
||||
/// Delete a key-value pair from the map.
|
||||
pub fn delete(&self, key: &str) -> LoroResult<()> {
|
||||
self.map.delete(key)
|
||||
|
|
|
@ -31,6 +31,13 @@ impl LoroMovableList {
|
|||
self.list.is_attached()
|
||||
}
|
||||
|
||||
/// If a detached container is attached, this method will return its corresponding attached handler.
|
||||
pub fn get_attached(&self) -> Option<Arc<LoroMovableList>> {
|
||||
self.list
|
||||
.get_attached()
|
||||
.map(|x| Arc::new(LoroMovableList { list: x }))
|
||||
}
|
||||
|
||||
/// Insert a value at the given position.
|
||||
pub fn insert(&self, pos: u32, v: Arc<dyn LoroValueLike>) -> LoroResult<()> {
|
||||
self.list.insert(pos as usize, v.as_loro_value())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{fmt::Display, sync::Arc};
|
||||
|
||||
use loro::{cursor::Side, LoroResult, PeerID, UpdateOptions, UpdateTimeoutError};
|
||||
use loro::{cursor::Side, ContainerTrait, LoroResult, PeerID, UpdateOptions, UpdateTimeoutError};
|
||||
use loro_internal::handler::TextDelta as InternalTextDelta;
|
||||
|
||||
use crate::{ContainerID, LoroValue, LoroValueLike, TextDelta};
|
||||
|
@ -31,6 +31,13 @@ impl LoroText {
|
|||
self.text.is_attached()
|
||||
}
|
||||
|
||||
/// If a detached container is attached, this method will return its corresponding attached handler.
|
||||
pub fn get_attached(&self) -> Option<Arc<LoroText>> {
|
||||
self.text
|
||||
.get_attached()
|
||||
.map(|x| Arc::new(LoroText { text: x }))
|
||||
}
|
||||
|
||||
/// Get the [ContainerID] of the text container.
|
||||
pub fn id(&self) -> ContainerID {
|
||||
self.text.id().into()
|
||||
|
|
|
@ -33,6 +33,13 @@ impl LoroTree {
|
|||
self.tree.is_attached()
|
||||
}
|
||||
|
||||
/// If a detached container is attached, this method will return its corresponding attached handler.
|
||||
pub fn get_attached(&self) -> Option<Arc<LoroTree>> {
|
||||
self.tree
|
||||
.get_attached()
|
||||
.map(|x| Arc::new(LoroTree { tree: x }))
|
||||
}
|
||||
|
||||
/// Create a new tree node and return the [`TreeID`].
|
||||
///
|
||||
/// If the `parent` is `None`, the created node is the root of a tree.
|
||||
|
|
Loading…
Reference in a new issue