Skip to main content

Storage

Trait Storage 

Source
pub trait Storage {
Show 20 methods // Required methods fn init(&mut self) -> Result<()>; fn is_initialized(&self) -> Result<bool>; fn reset(&mut self) -> Result<()>; fn save_context(&mut self, context: &Context) -> Result<()>; fn load_context(&self) -> Result<Option<Context>>; fn delete_context(&mut self) -> Result<()>; fn add_buffer(&mut self, buffer: &Buffer) -> Result<i64>; fn get_buffer(&self, id: i64) -> Result<Option<Buffer>>; fn get_buffer_by_name(&self, name: &str) -> Result<Option<Buffer>>; fn list_buffers(&self) -> Result<Vec<Buffer>>; fn update_buffer(&mut self, buffer: &Buffer) -> Result<()>; fn delete_buffer(&mut self, id: i64) -> Result<()>; fn buffer_count(&self) -> Result<usize>; fn add_chunks(&mut self, buffer_id: i64, chunks: &[Chunk]) -> Result<()>; fn get_chunks(&self, buffer_id: i64) -> Result<Vec<Chunk>>; fn get_chunk(&self, id: i64) -> Result<Option<Chunk>>; fn delete_chunks(&mut self, buffer_id: i64) -> Result<()>; fn chunk_count(&self, buffer_id: i64) -> Result<usize>; fn export_buffers(&self) -> Result<String>; fn stats(&self) -> Result<StorageStats>;
}
Expand description

Trait for persistent storage backends.

Implementations handle storage of RLM state including contexts, buffers, and chunks. All operations should be atomic where appropriate.

Note: This trait does not require Send + Sync as rlm-rs is a single-threaded CLI application. Implementations are not guaranteed to be thread-safe.

Required Methods§

Source

fn init(&mut self) -> Result<()>

Initializes storage (creates schema, runs migrations).

Should be idempotent - safe to call multiple times.

§Errors

Returns an error if schema creation or migration fails.

Source

fn is_initialized(&self) -> Result<bool>

Checks if storage is initialized.

§Errors

Returns an error if the check cannot be performed.

Source

fn reset(&mut self) -> Result<()>

Resets all stored state.

Deletes all data but preserves the schema.

§Errors

Returns an error if deletion fails.

Source

fn save_context(&mut self, context: &Context) -> Result<()>

Saves the current context state.

Creates or updates the context in storage.

§Errors

Returns an error if serialization or database write fails.

Source

fn load_context(&self) -> Result<Option<Context>>

Loads the context state.

Returns None if no context exists.

§Errors

Returns an error if database read or deserialization fails.

Source

fn delete_context(&mut self) -> Result<()>

Deletes the current context.

§Errors

Returns an error if deletion fails.

Source

fn add_buffer(&mut self, buffer: &Buffer) -> Result<i64>

Adds a buffer to storage.

Returns the assigned buffer ID.

§Errors

Returns an error if the buffer cannot be inserted.

Source

fn get_buffer(&self, id: i64) -> Result<Option<Buffer>>

Retrieves a buffer by ID.

§Errors

Returns an error if the query fails.

Source

fn get_buffer_by_name(&self, name: &str) -> Result<Option<Buffer>>

Retrieves a buffer by name.

§Errors

Returns an error if the query fails.

Source

fn list_buffers(&self) -> Result<Vec<Buffer>>

Lists all buffers.

§Errors

Returns an error if the query fails.

Source

fn update_buffer(&mut self, buffer: &Buffer) -> Result<()>

Updates an existing buffer.

§Errors

Returns an error if the buffer does not exist or update fails.

Source

fn delete_buffer(&mut self, id: i64) -> Result<()>

Deletes a buffer by ID.

Also deletes associated chunks.

§Errors

Returns an error if deletion fails.

Source

fn buffer_count(&self) -> Result<usize>

Returns the count of buffers.

§Errors

Returns an error if the count query fails.

Source

fn add_chunks(&mut self, buffer_id: i64, chunks: &[Chunk]) -> Result<()>

Adds chunks for a buffer.

Should be called after buffer is created.

§Errors

Returns an error if chunk insertion fails.

Source

fn get_chunks(&self, buffer_id: i64) -> Result<Vec<Chunk>>

Retrieves all chunks for a buffer.

§Errors

Returns an error if the query fails.

Source

fn get_chunk(&self, id: i64) -> Result<Option<Chunk>>

Retrieves a specific chunk by ID.

§Errors

Returns an error if the query fails.

Source

fn delete_chunks(&mut self, buffer_id: i64) -> Result<()>

Deletes all chunks for a buffer.

§Errors

Returns an error if deletion fails.

Source

fn chunk_count(&self, buffer_id: i64) -> Result<usize>

Returns the count of chunks for a buffer.

§Errors

Returns an error if the count query fails.

Source

fn export_buffers(&self) -> Result<String>

Exports all buffers as a concatenated string.

Used for the export-buffers command.

§Errors

Returns an error if buffer retrieval fails.

Source

fn stats(&self) -> Result<StorageStats>

Gets storage statistics.

§Errors

Returns an error if statistics cannot be gathered.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§