Struct bonsaidb_files::direct::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 descendants 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<Async<Database>, Config>
where Database: AsyncConnection + Clone, Config: FileConfig,

source

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

Return all direct descendants 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 async 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 async fn rename(&mut self, new_name: String) -> Result<(), Error>

Renames this file to the new name.

source

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

Deletes the file.

source

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

Returns the length of the file.

source

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

Returns true if this file contains no data.

source

pub async 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 async fn contents(&self) -> Result<Contents<Async<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 async 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 async 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) -> AsyncBufferedAppend<'_, Config, Database>

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

source

pub async 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 copy 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

Auto Trait Implementations§

§

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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