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: Cow<'static, str>) -> bool
pub fn update(&mut self, id: FileId, new_contents: Cow<'static, str>) -> 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,
write_to_disk: bool,
) -> Result<(), DatabaseError>
pub fn commit( &mut self, change_log: ChangeLog, write_to_disk: bool, ) -> Result<(), DatabaseError>
Commits a ChangeLog, applying all its recorded operations to the database
and optionally writing them to the filesystem.
§Arguments
change_log: The log of changes to apply.write_to_disk: Iftrue, changes for files that have a filesystem path will be written to disk in parallel.
§Errors
Returns a DatabaseError if the log cannot be consumed or if any
filesystem operation fails.
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(&self, id: &FileId) -> Result<Arc<File>, DatabaseError>
fn get(&self, id: &FileId) -> Result<Arc<File>, DatabaseError>
FileId. Read moreSource§fn get_ref(&self, id: &FileId) -> Result<&File, DatabaseError>
fn get_ref(&self, id: &FileId) -> Result<&File, DatabaseError>
FileId. Read moreSource§fn get_by_name(&self, name: &str) -> Result<Arc<File>, DatabaseError>
fn get_by_name(&self, name: &str) -> Result<Arc<File>, DatabaseError>
Source§fn get_by_path(&self, path: &Path) -> Result<Arc<File>, DatabaseError>
fn get_by_path(&self, path: &Path) -> Result<Arc<File>, DatabaseError>
Source§fn files(&self) -> impl Iterator<Item = Arc<File>>
fn files(&self) -> impl Iterator<Item = Arc<File>>
Source§fn files_with_type(
&self,
file_type: FileType,
) -> impl Iterator<Item = Arc<File>>
fn files_with_type( &self, file_type: FileType, ) -> impl Iterator<Item = Arc<File>>
FileType.Source§fn files_without_type(
&self,
file_type: FileType,
) -> impl Iterator<Item = Arc<File>>
fn files_without_type( &self, file_type: FileType, ) -> impl Iterator<Item = Arc<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.Auto Trait Implementations§
impl Freeze for Database
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
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