Database

Struct Database 

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

Source

pub fn new(configuration: DatabaseConfiguration<'a>) -> Self

Source

pub fn single(file: File, configuration: DatabaseConfiguration<'a>) -> Self

Source

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

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<'a> Clone for Database<'a>

Source§

fn clone(&self) -> Database<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> DatabaseReader for Database<'a>

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<'a> Debug for Database<'a>

Source§

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

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

impl<'de, 'a> Deserialize<'de> for Database<'a>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> Serialize for Database<'a>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,