pub struct SyncManager { /* private fields */ }Expand description
SyncManager provides high-level document synchronization with automatic subdoc handling.
This manager automatically:
- Creates SyncProviders for subdocuments
- Tracks and cleans up subdoc providers
- Emits unified events for both main doc and subdocs
§Example
use volt_client_grpc::{VoltClient, SyncManager};
use yrs::Doc;
let doc = Doc::new();
let (mut manager, mut events) = SyncManager::new(doc, "@my-sync-db", "my-document");
// Start syncing
manager.start(&client).await?;
// Handle events
while let Some(event) = events.recv().await {
match event {
SyncManagerEvent::Synced => println!("Document synced!"),
SyncManagerEvent::SubdocUpdated { guid, doc } => {
println!("Subdoc {} updated", guid);
}
_ => {}
}
}Implementations§
Source§impl SyncManager
impl SyncManager
Sourcepub fn new(
doc: Doc,
database_id: impl Into<String>,
document_id: impl Into<String>,
) -> (Self, Receiver<SyncManagerEvent>)
pub fn new( doc: Doc, database_id: impl Into<String>, document_id: impl Into<String>, ) -> (Self, Receiver<SyncManagerEvent>)
Sourcepub fn set_auto_sync_subdocs(&mut self, enabled: bool)
pub fn set_auto_sync_subdocs(&mut self, enabled: bool)
Enable or disable automatic subdoc syncing.
When enabled (default), the manager automatically creates SyncProviders for subdocuments detected in the main document.
Sourcepub fn database_id(&self) -> &str
pub fn database_id(&self) -> &str
Get the database ID.
Sourcepub fn document_id(&self) -> &str
pub fn document_id(&self) -> &str
Get the document ID.
Sourcepub fn subdoc_guids(&self) -> Vec<String>
pub fn subdoc_guids(&self) -> Vec<String>
Get the list of currently synced subdoc GUIDs.
Sourcepub fn is_subdoc_synced(&self, guid: &str) -> bool
pub fn is_subdoc_synced(&self, guid: &str) -> bool
Check if a subdoc is being synced.
Sourcepub fn get_subdoc(&self, guid: &str) -> Option<Doc>
pub fn get_subdoc(&self, guid: &str) -> Option<Doc>
Get a clone of a subdoc by GUID.
Returns None if the subdoc is not currently being synced.
Sourcepub async fn start(&mut self, client: &VoltClient) -> Result<()>
pub async fn start(&mut self, client: &VoltClient) -> Result<()>
Start synchronization.
This starts the main document provider and sets up event handling.
If auto_sync_subdocs is enabled, subdocs will be automatically synced.
§Arguments
client- The VoltClient to use for synchronization
Sourcepub async fn start_with_options(
&mut self,
client: &VoltClient,
read_only: bool,
read_only_fallback: bool,
) -> Result<()>
pub async fn start_with_options( &mut self, client: &VoltClient, read_only: bool, read_only_fallback: bool, ) -> Result<()>
Start synchronization with options.
§Arguments
client- The VoltClient to useread_only- If true, only receive updatesread_only_fallback- If true, downgrade to read-only if write access denied
Sourcepub async fn run_event_loop(&mut self, client: &VoltClient)
pub async fn run_event_loop(&mut self, client: &VoltClient)
Run the event processing loop.
This should be called after start() to process events.
It will run until the connection is closed or an error occurs.
§Arguments
client- The VoltClient (needed for starting subdoc providers)
§Example
// In a spawned task:
manager.start(&client).await?;
manager.run_event_loop(&client).await;Sourcepub fn root_map_to_json(&self) -> Value
pub fn root_map_to_json(&self) -> Value
Get the main document’s root map as JSON.
Sourcepub fn root_map_to_json_string(&self) -> String
pub fn root_map_to_json_string(&self) -> String
Get the main document’s root map as a JSON string.
Auto Trait Implementations§
impl Freeze for SyncManager
impl !RefUnwindSafe for SyncManager
impl !Send for SyncManager
impl !Sync for SyncManager
impl Unpin for SyncManager
impl !UnwindSafe for SyncManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request