Struct freqfs::Dir

source ·
pub struct Dir<FE> { /* private fields */ }
Expand description

A filesystem directory

Implementations§

source§

impl<FE: Send + Sync> Dir<FE>

source

pub fn path(&self) -> &Path

Borrow the Path of this Dir.

source

pub fn contains<Q: Name + Display + ?Sized>(&self, name: &Q) -> bool

Return true if this Dir has an entry with the given name.

source

pub fn create_dir(&mut self, name: String) -> Result<DirLock<FE>, Error>

Create and return a new subdirectory of this Dir.

source

pub fn create_dir_unique(&mut self) -> Result<(Uuid, DirLock<FE>), Error>

Create and return a new subdirectory of this Dir with a unique name.

source

pub fn entries(&self) -> impl Iterator<Item = &DirEntry<FE>>

Return an Iterator over the entries in this Dir.

source

pub fn files(&self) -> impl Iterator<Item = &FileLock<FE>>

Return an Iterator over the file entries in this Dir.

source

pub fn get_or_create_dir(&mut self, name: String) -> Result<DirLock<FE>, Error>

Return a new subdirectory of this Dir, creating it if it doesn’t already exist.

source

pub fn get<Q: Name + ?Sized>(&self, name: &Q) -> Option<&DirEntry<FE>>

Get the entry with the given name from this Dir.

source

pub fn get_dir<Q: Name + ?Sized>(&self, name: &Q) -> Option<&DirLock<FE>>

Get the subdirectory with the given name from this Dir, if present.

Also returns None if the entry at name is a file.

source

pub fn get_file<Q: Name + ?Sized>(&self, name: &Q) -> Option<&FileLock<FE>>

Get the file with the given name from this Dir, if present.

Also returns None if the entry at name is a directory.

source

pub fn is_empty(&self) -> bool

Return true if this Dir contains no entries.

source

pub fn iter(&self) -> impl Iterator<Item = (&String, &DirEntry<FE>)>

Return an Iterator over the entries in this Dir.

source

pub fn len(&self) -> usize

Return the number of entries in this Dir.

source

pub fn names(&self) -> impl Iterator<Item = &String>

Return an Iterator over the names of the entries in this Dir.

source

pub async fn read_file<Q, F>( &self, name: &Q ) -> Result<FileReadGuard<'_, F>, Error>
where Q: Name + Display + ?Sized, F: FileLoad, FE: AsType<F>,

Convenience method to lock a file for reading. Returns a “not found” error if the there is no file with the given name.

source

pub async fn read_file_owned<Q, F>( &self, name: &Q ) -> Result<FileReadGuardOwned<FE, F>, Error>
where Q: Name + Display + ?Sized, F: FileLoad, FE: AsType<F>,

Convenience method to lock a file for reading. Returns a “not found” error if the there is no file with the given name.

source

pub async fn write_file<Q, F>( &self, name: &Q ) -> Result<FileWriteGuard<'_, F>, Error>
where Q: Name + Display + ?Sized, F: FileLoad, FE: AsType<F>,

Convenience method to lock a file for writing. Returns a “not found” error if the there is no file with the given name.

source

pub async fn write_file_owned<Q, F>( &self, name: &Q ) -> Result<FileWriteGuardOwned<FE, F>, Error>
where Q: Name + Display + ?Sized, F: FileLoad, FE: AsType<F>,

Convenience method to lock a file for writing. Returns a “not found” error if the there is no file with the given name.

source§

impl<FE: Send + Sync> Dir<FE>

source

pub fn create_file<F>( &mut self, name: String, contents: F, size: usize ) -> Result<FileLock<FE>, Error>
where FE: From<F>,

Create a new file in this Dir with the given contents.

source

pub fn create_file_unique<F>( &mut self, contents: F, size: usize ) -> Result<(Uuid, FileLock<FE>), Error>
where FE: From<F>,

Create a new file in this Dir with a unique name and the given contents.

source

pub fn copy_dir_from<'a>( &'a mut self, name: String, source: &'a DirLock<FE> ) -> Pin<Box<dyn Future<Output = Result<DirLock<FE>, Error>> + Send + 'a>>
where FE: Clone,

Create or overwrite the directory at name by copying from source, without necessarily loading its contents into the cache.

source

pub async fn copy_file_from( &mut self, name: String, source: &FileLock<FE> ) -> Result<FileLock<FE>, Error>
where FE: Clone,

Create or overwrite the file at name by copying from source, without necessarily loading source into the cache.

source

pub fn delete<'a, Q>( &'a mut self, name: &'a Q ) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>
where Q: Name + Send + Sync + ?Sized,

Delete the entry with the given name from this Dir.

Returns true if there was an entry present.

This will cause a deadlock if there are still active references to the deleted entry of this directory, i.e. if a lock cannot be acquired any child to delete (recursively)!

Make sure to call Dir::sync to delete any contents on the filesystem if it’s possible for an new entry with the same name to be created later.

source

pub fn sync( &mut self ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>
where FE: for<'a> FileSave<'a>,

Synchronize the contents of this directory with the filesystem.

source

pub fn truncate<'a>( &'a mut self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>

Delete all entries from this Dir.

This will cause a deadlock if there are still active references to the contents of this directory, i.e. if a lock cannot be acquired on any child of this Dir (recursively)!

Make sure to call Dir::sync to delete any contents on the filesystem if it’s possible for an new entry with the same name to be created later. Alternately, call Dir::truncate_and_sync.

source

pub fn truncate_and_sync<'a>( &'a mut self ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Delete all entries from this Dir on the filesystem.

This will cause a deadlock if there are still active references to the contents of this directory, i.e. if a lock cannot be acquired on any child of this Dir (recursively)!

Trait Implementations§

source§

impl<FE> Debug for Dir<FE>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<FE> !RefUnwindSafe for Dir<FE>

§

impl<FE> Send for Dir<FE>
where FE: Send + Sync,

§

impl<FE> Sync for Dir<FE>
where FE: Send + Sync,

§

impl<FE> Unpin for Dir<FE>

§

impl<FE> !UnwindSafe for Dir<FE>

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<F, T> CastFrom<F> for T
where T: From<F>,

source§

fn cast_from(f: F) -> T

Cast an instance of T into an instance of Self.
source§

impl<T, F> CastInto<F> for T
where F: CastFrom<T>,

source§

fn cast_into(self) -> F

Cast an instance of Self into an instance of T.
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<F> Match for F

source§

fn matches<T>(&self) -> bool
where T: TryCastFrom<Self>,

Returns true if self can be cast into the target type T.
source§

impl<F, T> TryCastFrom<F> for T
where T: CastFrom<F>,

source§

fn can_cast_from(_: &F) -> bool

Test if value can be cast into Self.
source§

fn opt_cast_from(f: F) -> Option<T>

Returns Some(Self) if the source value can be cast into Self, otherwise None.
source§

fn try_cast_from<Err, OnErr>(value: T, on_err: OnErr) -> Result<Self, Err>
where OnErr: FnOnce(&T) -> Err,

Returns Ok(Self) if the source value can be cast into Self, otherwise calls on_err.
source§

impl<F, T> TryCastInto<T> for F
where T: TryCastFrom<F>,

source§

fn can_cast_into(&self) -> bool

Test if self can be cast into T.
source§

fn opt_cast_into(self) -> Option<T>

Returns Some(T) if self can be cast into T, otherwise None.
source§

fn try_cast_into<Err, OnErr>(self, on_err: OnErr) -> Result<T, Err>
where OnErr: FnOnce(&Self) -> Err,

Returns Ok(T) if self can be cast into T, otherwise calls on_err.
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.