Struct Database

Source
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

Source

pub fn new() -> Self

Creates a new, empty Database.

Source

pub fn add(&mut self, file: File)

Adds a file to the database, overwriting any existing file with the same name.

Source

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.

Source

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.

Source

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: If true, 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.

Source

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

Source§

fn get_id(&self, name: &str) -> Option<FileId>

Retrieves a file’s stable ID using its logical name.
Source§

fn get(&self, id: &FileId) -> Result<Arc<File>, DatabaseError>

Retrieves a reference to a file using its stable FileId. Read more
Source§

fn get_ref(&self, id: &FileId) -> Result<&File, DatabaseError>

Retrieves a reference to a file using its stable FileId. Read more
Source§

fn get_by_name(&self, name: &str) -> Result<Arc<File>, DatabaseError>

Retrieves a reference to a file using its logical name. Read more
Source§

fn get_by_path(&self, path: &Path) -> Result<Arc<File>, DatabaseError>

Retrieves a reference to a file by its absolute filesystem path. Read more
Source§

fn files(&self) -> impl Iterator<Item = Arc<File>>

Returns an iterator over all files in the database. Read more
Source§

fn len(&self) -> usize

Returns the total number of files in the database.
Source§

fn files_with_type( &self, file_type: FileType, ) -> impl Iterator<Item = Arc<File>>

Returns an iterator over all files of a specific FileType.
Source§

fn files_without_type( &self, file_type: FileType, ) -> impl Iterator<Item = Arc<File>>

Returns an iterator over all files that do not match a specific FileType.
Source§

fn file_ids(&self) -> impl Iterator<Item = FileId>

Returns an iterator over the stable IDs of all files in the database.
Source§

fn file_ids_with_type( &self, file_type: FileType, ) -> impl Iterator<Item = FileId>

Returns an iterator over the stable IDs of all files of a specific FileType.
Source§

fn file_ids_without_type( &self, file_type: FileType, ) -> impl Iterator<Item = FileId>

Returns an iterator over the stable IDs of all files that do not match a specific FileType.
Source§

fn is_empty(&self) -> bool

Returns true if the database contains no files.
Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Database

Source§

fn default() -> Database

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more