pub struct Database<'a> { /* private fields */ }Expand description
Mutable database for managing project files with add/update/delete operations.
Implementations§
Source§impl<'a> Database<'a>
impl<'a> Database<'a>
pub fn new(configuration: DatabaseConfiguration<'a>) -> Self
pub fn single(file: File, configuration: DatabaseConfiguration<'a>) -> Self
pub fn add(&mut self, file: File) -> FileId
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<'a> DatabaseReader for Database<'a>
impl<'a> DatabaseReader for Database<'a>
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.Source§impl<'de, 'a> Deserialize<'de> for Database<'a>
impl<'de, 'a> Deserialize<'de> for Database<'a>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl<'a> Freeze for Database<'a>
impl<'a> RefUnwindSafe for Database<'a>
impl<'a> Send for Database<'a>
impl<'a> Sync for Database<'a>
impl<'a> Unpin for Database<'a>
impl<'a> UnwindSafe for Database<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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