SyncDocument

Struct SyncDocument 

Source
pub struct SyncDocument { /* private fields */ }
Available on crate feature concurrency only.
Expand description

Thread-safe wrapper for EditorDocument

Provides synchronized access to an EditorDocument, allowing multiple threads to safely read and modify the document. Uses RwLock for efficient concurrent reads.

Note: Due to Bump allocator using Cell types, EditorDocument is not Sync. SyncDocument provides thread-safe access through RwLock synchronization. The RwLock ensures that only one thread can write at a time, and the interior mutability of Bump is safe within a single thread.

Implementations§

Source§

impl SyncDocument

Source

pub fn new(document: EditorDocument) -> Self

Create a new thread-safe document

Source

pub fn from_document(document: EditorDocument) -> Self

Create from an existing document

Source

pub fn read(&self) -> Result<RwLockReadGuard<'_, EditorDocument>>

Get a read-only reference to the document

Source

pub fn write(&self) -> Result<RwLockWriteGuard<'_, EditorDocument>>

Get a mutable reference to the document

Source

pub fn execute_command<C: EditorCommand>( &self, command: C, ) -> Result<CommandResult>

Execute a command atomically

Source

pub fn try_read(&self) -> Option<RwLockReadGuard<'_, EditorDocument>>

Try to get a read-only reference without blocking

Source

pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, EditorDocument>>

Try to get a mutable reference without blocking

Source

pub fn text(&self) -> Result<String>

Get the document text safely

Source

pub fn len(&self) -> Result<usize>

Get document length safely

Source

pub fn is_empty(&self) -> Result<bool>

Check if document is empty safely

Source

pub fn id(&self) -> Result<String>

Get document ID safely

Source

pub fn with_read<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&EditorDocument) -> R,

Perform an operation with read access

Source

pub fn with_write<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&mut EditorDocument) -> Result<R>,

Perform an operation with write access

Source

pub fn clone_document(&self) -> Result<EditorDocument>

Clone the underlying document

Source

pub fn validate(&self) -> Result<()>

Validate the document (basic parsing check)

Source

pub fn validate_comprehensive(&self) -> Result<Vec<ValidationIssue>>

Validate comprehensive (requires mutable access for LazyValidator)

Trait Implementations§

Source§

impl Clone for SyncDocument

Source§

fn clone(&self) -> SyncDocument

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SyncDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.