pub struct Database<'config> { /* private fields */ }Expand description
Mutable database for managing project files with add/update/delete operations.
Implementations§
Source§impl<'config> Database<'config>
impl<'config> Database<'config>
pub fn new(configuration: DatabaseConfiguration<'config>) -> Self
pub fn single(file: File, configuration: DatabaseConfiguration<'config>) -> Self
Sourcepub fn into_static(self) -> Database<'static>
pub fn into_static(self) -> Database<'static>
Converts this database into one that owns its configuration.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more files.
Sourcepub fn merge_base(&mut self, base: Database<'_>)
pub fn merge_base(&mut self, base: Database<'_>)
Adds files from a base database without replacing files already present in this database.
This is useful when project files and a built-in prelude are loaded independently: project files retain precedence while missing built-in files are moved into the project database.
pub fn add(&mut self, file: File) -> FileId
Sourcepub fn update(&mut self, id: FileId, new_contents: Cow<'static, [u8]>) -> bool
pub fn update(&mut self, id: FileId, new_contents: Cow<'static, [u8]>) -> bool
Updates a file’s content using its stable FileId.
This recalculates derived data like file size, line endings, and FileRevision.
If another ReadDatabase snapshot holds a reference to the file (preventing in-place
mutation), a new Arc<File> is created with the updated contents.
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.
Shares file data and sorts it by ID. Name and path lookups build their indexes on first use. The snapshot stays unchanged when the original database changes.
Trait Implementations§
Source§impl DatabaseReader for Database<'_>
impl DatabaseReader for Database<'_>
Source§fn get_id(&self, name: &[u8]) -> Option<FileId>
fn get_id(&self, name: &[u8]) -> 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: &[u8]) -> Result<Arc<File>, DatabaseError>
fn get_by_name(&self, name: &[u8]) -> 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<'config> Freeze for Database<'config>
impl<'config> RefUnwindSafe for Database<'config>
impl<'config> Send for Database<'config>
impl<'config> Sync for Database<'config>
impl<'config> Unpin for Database<'config>
impl<'config> UnsafeUnpin for Database<'config>
impl<'config> UnwindSafe for Database<'config>
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