pub struct Database { /* private fields */ }Expand description
A mutable database for managing a collection of project files.
This struct acts as the primary “builder” for your file set. It is optimized
for efficient additions, updates, and deletions. Once you have loaded all
files and performed any initial modifications, you can create a high-performance,
immutable snapshot for fast querying by calling read_only.
Implementations§
Source§impl Database
impl Database
Sourcepub fn add(&mut self, file: File)
pub fn add(&mut self, file: File)
Adds a file to the database, overwriting any existing file with the same name.
Sourcepub fn update(&mut self, id: FileId, new_contents: String) -> bool
pub fn update(&mut self, id: FileId, new_contents: String) -> bool
Updates a file’s content in-place using its stable FileId.
This recalculates derived data like file size, line endings, and FileRevision.
Returns true if a file with the given ID was found and updated.
Sourcepub fn delete(&mut self, id: FileId) -> bool
pub fn delete(&mut self, id: FileId) -> bool
Deletes a file from the database using its stable FileId.
Returns true if a file with the given ID was found and removed.
Sourcepub fn commit(&mut self, change_log: ChangeLog) -> Result<(), DatabaseError>
pub fn commit(&mut self, change_log: ChangeLog) -> Result<(), DatabaseError>
Commits a ChangeLog, applying all its recorded operations to the database.
This method consumes the log and applies each Change sequentially.
It will fail if other references to the ChangeLog still exist.
§Errors
Returns a DatabaseError if the log cannot be consumed.
Sourcepub fn read_only(&self) -> ReadDatabase
pub fn read_only(&self) -> ReadDatabase
Creates an independent, immutable snapshot of the database.
This is a potentially expensive one-time operation as it clones all file
data. The resulting ReadDatabase is highly optimized for fast reads and
guarantees a deterministic iteration order. The original Database is not
consumed and can continue to be used.
Trait Implementations§
Source§impl DatabaseReader for Database
impl DatabaseReader for Database
Source§fn get_id(&self, name: &str) -> Option<FileId>
fn get_id(&self, name: &str) -> Option<FileId>
Source§fn get_by_id(&self, id: &FileId) -> Result<&File, DatabaseError>
fn get_by_id(&self, id: &FileId) -> Result<&File, DatabaseError>
FileId. Read moreSource§fn get_by_name(&self, name: &str) -> Result<&File, DatabaseError>
fn get_by_name(&self, name: &str) -> Result<&File, DatabaseError>
Source§fn get_by_path(&self, path: &Path) -> Result<&File, DatabaseError>
fn get_by_path(&self, path: &Path) -> Result<&File, DatabaseError>
Source§fn files(&self) -> impl Iterator<Item = &File>
fn files(&self) -> impl Iterator<Item = &File>
fn get_name(&self, id: &FileId) -> Option<&str>
Source§fn files_with_type(&self, file_type: FileType) -> impl Iterator<Item = &File>
fn files_with_type(&self, file_type: FileType) -> impl Iterator<Item = &File>
FileType.Source§fn files_without_type(&self, file_type: FileType) -> impl Iterator<Item = &File>
fn files_without_type(&self, file_type: FileType) -> impl Iterator<Item = &File>
FileType.Source§fn file_ids(&self) -> impl Iterator<Item = FileId>
fn file_ids(&self) -> impl Iterator<Item = FileId>
Source§fn file_ids_with_type(
&self,
file_type: FileType,
) -> impl Iterator<Item = FileId>
fn file_ids_with_type( &self, file_type: FileType, ) -> impl Iterator<Item = FileId>
FileType.