pub struct Workspace { /* private fields */ }Expand description
A workspace for managing indexed documents.
Uses LRU cache for loaded documents to balance memory usage and access performance.
§Thread Safety
The workspace is thread-safe when used with a thread-safe backend.
Read operations only require &self.
Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn with_backend(backend: Arc<dyn StorageBackend>) -> Result<Self>
pub fn with_backend(backend: Arc<dyn StorageBackend>) -> Result<Self>
Sourcepub fn with_backend_and_options(
backend: Arc<dyn StorageBackend>,
options: WorkspaceOptions,
) -> Result<Self>
pub fn with_backend_and_options( backend: Arc<dyn StorageBackend>, options: WorkspaceOptions, ) -> Result<Self>
Create a workspace with backend and options.
Sourcepub fn new(path: impl Into<PathBuf>) -> Result<Self>
pub fn new(path: impl Into<PathBuf>) -> Result<Self>
Create a new file-based workspace at the given path.
This is a convenience method that creates a FileBackend internally.
Sourcepub fn with_cache_size(
path: impl Into<PathBuf>,
cache_size: usize,
) -> Result<Self>
pub fn with_cache_size( path: impl Into<PathBuf>, cache_size: usize, ) -> Result<Self>
Create a new workspace with custom LRU cache size.
Sourcepub fn with_options(
path: impl Into<PathBuf>,
options: WorkspaceOptions,
) -> Result<Self>
pub fn with_options( path: impl Into<PathBuf>, options: WorkspaceOptions, ) -> Result<Self>
Create a new workspace with custom options.
Sourcepub fn open(path: impl Into<PathBuf> + Clone) -> Result<Self>
pub fn open(path: impl Into<PathBuf> + Clone) -> Result<Self>
Open an existing workspace, or create if it doesn’t exist.
Sourcepub fn open_with_cache_size(
path: impl Into<PathBuf> + Clone,
cache_size: usize,
) -> Result<Self>
pub fn open_with_cache_size( path: impl Into<PathBuf> + Clone, cache_size: usize, ) -> Result<Self>
Open with custom cache size.
Sourcepub fn open_with_options(
path: impl Into<PathBuf> + Clone,
options: WorkspaceOptions,
) -> Result<Self>
pub fn open_with_options( path: impl Into<PathBuf> + Clone, options: WorkspaceOptions, ) -> Result<Self>
Open with custom options.
Sourcepub fn backend(&self) -> &dyn StorageBackend
pub fn backend(&self) -> &dyn StorageBackend
Get the storage backend.
Sourcepub fn list_documents(&self) -> Vec<&str>
pub fn list_documents(&self) -> Vec<&str>
List all document IDs in the workspace.
Sourcepub fn get_meta(&self, id: &str) -> Option<&DocumentMetaEntry>
pub fn get_meta(&self, id: &str) -> Option<&DocumentMetaEntry>
Get metadata for a document.
Sourcepub fn add(&mut self, doc: &PersistedDocument) -> Result<()>
pub fn add(&mut self, doc: &PersistedDocument) -> Result<()>
Add a document to the workspace.
Sourcepub fn load(&self, id: &str) -> Result<Option<PersistedDocument>>
pub fn load(&self, id: &str) -> Result<Option<PersistedDocument>>
Load a document from the workspace.
Uses LRU cache: returns cached version if available, otherwise loads from backend and caches it.
Sourcepub fn cache_utilization(&self) -> f64
pub fn cache_utilization(&self) -> f64
Get cache utilization (0.0 to 1.0).
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Get cache statistics.
Sourcepub fn clear_cache(&self) -> Result<()>
pub fn clear_cache(&self) -> Result<()>
Clear the LRU cache (does not remove documents from workspace).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Workspace
impl !RefUnwindSafe for Workspace
impl Send for Workspace
impl Sync for Workspace
impl Unpin for Workspace
impl UnsafeUnpin for Workspace
impl !UnwindSafe for Workspace
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more