Skip to main content

SyncManager

Struct SyncManager 

Source
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

Source

pub fn new( doc: Doc, database_id: impl Into<String>, document_id: impl Into<String>, ) -> (Self, Receiver<SyncManagerEvent>)

Create a new SyncManager.

§Arguments
  • doc - The Y.js document to sync
  • database_id - ID/alias of the sync database
  • document_id - ID of the document to sync
§Returns

A tuple of (SyncManager, event_receiver)

Source

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.

Source

pub fn doc(&self) -> &Doc

Get a reference to the main document.

Source

pub fn doc_clone(&self) -> Doc

Get a clone of the main document.

Source

pub fn database_id(&self) -> &str

Get the database ID.

Source

pub fn document_id(&self) -> &str

Get the document ID.

Source

pub fn subdoc_guids(&self) -> Vec<String>

Get the list of currently synced subdoc GUIDs.

Source

pub fn is_subdoc_synced(&self, guid: &str) -> bool

Check if a subdoc is being synced.

Source

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.

Source

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
Source

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 use
  • read_only - If true, only receive updates
  • read_only_fallback - If true, downgrade to read-only if write access denied
Source

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;
Source

pub async fn stop(&mut self)

Stop all synchronization.

Source

pub fn root_map_to_json(&self) -> Value

Get the main document’s root map as JSON.

Source

pub fn root_map_to_json_string(&self) -> String

Get the main document’s root map as a JSON string.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more