Skip to main content

Database

Struct Database 

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

Source

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

Source

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

Source

pub fn into_static(self) -> Database<'static>

Converts this database into one that owns its configuration.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more files.

Source

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.

Source

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

Source

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.

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.

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl DatabaseReader for Database<'_>

Source§

fn get_id(&self, name: &[u8]) -> 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: &[u8]) -> 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<'config> Debug for Database<'config>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'config> Forget for Database<'config>

§

impl<'config> Freeze for Database<'config>
where *const u8 is !null: Freeze, PhantomData<(Cow<'static, [u8]>, Arc<File>)>: Freeze, PhantomData<(FileId, Cow<'static, [u8]>)>: Freeze, &'config Path: Freeze, PathBuf: Freeze, PhantomData<Cow<'config, [u8]>>: Freeze, PhantomData<Exclusion<'config>>: Freeze,

§

impl<'config> Move for Database<'config>

§

impl<'config> RefUnwindSafe for Database<'config>

§

impl<'config> Send for Database<'config>
where RawTable<(Cow<'static, [u8]>, Arc<File>)>: Send, RawTable<(FileId, Cow<'static, [u8]>)>: Send, &'config Path: Send, PathBuf: Send, RawVecInner: Send, &'config [u8]: Send, Vec<u8>: Send, &'config str: Send, String: Send,

§

impl<'config> Sync for Database<'config>
where RawTable<(Cow<'static, [u8]>, Arc<File>)>: Sync, RawTable<(FileId, Cow<'static, [u8]>)>: Sync, PathBuf: Sync, RawVecInner: Sync, Vec<u8>: Sync, String: Sync,

§

impl<'config> Unpin for Database<'config>
where *const u8 is !null: Unpin, &'static [u8]: Unpin, Vec<u8>: Unpin, Arc<File>: Unpin, &'config Path: Unpin, PathBuf: Unpin, &'config [u8]: Unpin, &'config str: Unpin, String: Unpin,

§

impl<'config> UnsafeUnpin for Database<'config>

§

impl<'config> UnwindSafe for Database<'config>
where HashMap<Cow<'static, [u8]>, Arc<File>, RandomState>: UnwindSafe, HashMap<FileId, Cow<'static, [u8]>, RandomState>: UnwindSafe, &'config Path: UnwindSafe, PathBuf: UnwindSafe, RawVecInner: UnwindSafe, &'config [u8]: UnwindSafe, Vec<u8>: UnwindSafe, &'config str: UnwindSafe, String: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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