File

Struct File 

Source
pub struct File<Database: Clone, Config: FileConfig = BonsaiFiles> { /* private fields */ }
Expand description

A handle to a file stored in a database.

Implementations§

Source§

impl<Database, Config> File<Blocking<Database>, Config>
where Database: Connection + Clone, Config: FileConfig,

Source

pub fn children(&self) -> Result<Vec<Self>, Error>

Return all direct descendents of this file. For example, consider this list of files:

  • /top-level
  • /top-level/sub-level
  • /top-level/sub-level/file.txt

If this instance were /top-level, this function would return sub-level but not sub-level/file.txt.

Source

pub fn move_to(&mut self, new_path: &str) -> Result<(), Error>

Moves this file to a new location. If new_path ends with a /, the file will be moved to that path with its name preserved. Otherwise, the file will be renamed as part of the move.

For example, moving /a/file.txt to /b/ will result in the full path being /b/file.txt. Moving /a/file.txt to /b/new-name.txt will result in the full path being /b/new-name.txt.

Source

pub fn rename(&mut self, new_name: String) -> Result<(), Error>

Renames this file to the new name.

Source

pub fn delete(&self) -> Result<(), Error>

Deletes the file.

Source

pub fn len(&mut self) -> Result<u64, Error>

Returns the length of the file.

Source

pub fn is_empty(&mut self) -> Result<bool, Error>

Returns true if this file contains no data.

Source

pub fn last_appended_at( &mut self, ) -> Result<Option<TimestampAsNanoseconds>, Error>

Returns the timestamp of the last append to the file. This function returns 0 when the file is empty, even if the file was previously written to.

Source

pub fn contents(&self) -> Result<Contents<Blocking<Database>, Config>, Error>

Returns the contents of the file, which allows random and buffered access to the file stored in the database.

The default buffer size is ten times Config::BLOCK_SIZE.

Source

pub fn truncate(&self, new_length: u64, from: Truncate) -> Result<(), Error>

Truncates the file, removing data from either the start or end of the file until the file is within Config::BLOCK_SIZE of new_length. Truncating currently will not split a block, causing the resulting length to not always match the length requested.

If new_length is 0 and this call succeeds, the file’s length is guaranteed to be 0.

Source

pub fn append(&self, data: &[u8]) -> Result<(), Error>

Appends data to the end of the file. The data will be split into chunks no larger than Config::BLOCK_SIZE when stored in the database.

Source

pub fn append_buffered(&mut self) -> BufferedAppend<'_, Config, Database>

Returns a writer that will buffer writes to the end of the file.

Source

pub fn update_metadata(&mut self) -> Result<(), Error>

Stores changes to the metadata of this document.

Source§

impl<Database, Config> File<Database, Config>
where Database: Clone, Config: FileConfig,

Source

pub fn id(&self) -> u32

Returns the unique id of this file. The file id is only unique within a single database and FileConfig.

Source

pub fn containing_path(&self) -> &str

Returns the path containing this file. For example, if the full path to the file is /some-path/file.txt, this function will return /some-path/.

Source

pub fn name(&self) -> &str

Returns the name of this file.

Source

pub fn path(&self) -> String

Returns the absolute path of this file.

Source

pub fn created_at(&self) -> TimestampAsNanoseconds

Returns the timestamp the file was created at.

Source

pub fn metadata(&self) -> &Config::Metadata

Returns the metadata for this file.

Source

pub fn metadata_mut(&mut self) -> &mut Config::Metadata

Returns mutable access metadata for this file. Modifying the metadata will not update it in the database. Be sure to call update_metadata() or another operation that persists the file.

Trait Implementations§

Source§

impl<Database: Clone, Config: FileConfig> Clone for File<Database, Config>

Source§

fn clone(&self) -> Self

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<Database: Clone, Config: FileConfig> Debug for File<Database, Config>

Source§

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

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

impl<Database, Config> PartialEq for File<Database, Config>
where Database: Clone, Config: FileConfig,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<Database, Config> Freeze for File<Database, Config>
where Database: Freeze, <Config as FileConfig>::Metadata: Freeze,

§

impl<Database, Config> RefUnwindSafe for File<Database, Config>
where Database: RefUnwindSafe, <Config as FileConfig>::Metadata: RefUnwindSafe, Config: RefUnwindSafe,

§

impl<Database, Config> Send for File<Database, Config>
where Database: Send,

§

impl<Database, Config> Sync for File<Database, Config>
where Database: Sync,

§

impl<Database, Config> Unpin for File<Database, Config>
where Database: Unpin, <Config as FileConfig>::Metadata: Unpin,

§

impl<Database, Config> UnwindSafe for File<Database, Config>
where Database: UnwindSafe, <Config as FileConfig>::Metadata: UnwindSafe, Config: 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, 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> Same for T

Source§

type Output = T

Should always be Self
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.