pub struct Dir<FE> { /* private fields */ }
Expand description
A filesystem directory
Implementations§
source§impl<FE: Send + Sync> Dir<FE>
impl<FE: Send + Sync> Dir<FE>
sourcepub fn contains<Q: Name + Display + ?Sized>(&self, name: &Q) -> bool
pub fn contains<Q: Name + Display + ?Sized>(&self, name: &Q) -> bool
Return true
if this Dir
has an entry with the given name
.
sourcepub fn create_dir(&mut self, name: String) -> Result<DirLock<FE>, Error>
pub fn create_dir(&mut self, name: String) -> Result<DirLock<FE>, Error>
Create and return a new subdirectory of this Dir
.
sourcepub fn create_dir_unique(&mut self) -> Result<(Uuid, DirLock<FE>), Error>
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.
sourcepub fn get_or_create_dir(&mut self, name: String) -> Result<DirLock<FE>, Error>
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.
sourcepub fn get<Q: Name + ?Sized>(&self, name: &Q) -> Option<&DirEntry<FE>>
pub fn get<Q: Name + ?Sized>(&self, name: &Q) -> Option<&DirEntry<FE>>
Get the entry with the given name
from this Dir
.
sourcepub fn get_dir<Q: Name + ?Sized>(&self, name: &Q) -> Option<&DirLock<FE>>
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.
sourcepub fn get_file<Q: Name + ?Sized>(&self, name: &Q) -> Option<&FileLock<FE>>
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.
sourcepub async fn read_file<Q, F>(
&self,
name: &Q
) -> Result<FileReadGuard<'_, F>, Error>
pub async fn read_file<Q, F>( &self, name: &Q ) -> Result<FileReadGuard<'_, F>, Error>
Convenience method to lock a file for reading.
Returns a “not found” error if the there is no file with the given name
.
sourcepub async fn read_file_owned<Q, F>(
&self,
name: &Q
) -> Result<FileReadGuardOwned<FE, F>, Error>
pub async fn read_file_owned<Q, F>( &self, name: &Q ) -> Result<FileReadGuardOwned<FE, F>, Error>
Convenience method to lock a file for reading.
Returns a “not found” error if the there is no file with the given name
.
sourcepub async fn write_file<Q, F>(
&self,
name: &Q
) -> Result<FileWriteGuard<'_, F>, Error>
pub async fn write_file<Q, F>( &self, name: &Q ) -> Result<FileWriteGuard<'_, F>, Error>
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>
impl<FE: Send + Sync> Dir<FE>
sourcepub fn create_file<F>(
&mut self,
name: String,
contents: F,
size: usize
) -> Result<FileLock<FE>, Error>where
FE: From<F>,
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
.
sourcepub fn create_file_unique<F>(
&mut self,
contents: F,
size: usize
) -> Result<(Uuid, FileLock<FE>), Error>where
FE: From<F>,
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
.
sourcepub 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,
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.
sourcepub async fn copy_file_from(
&mut self,
name: String,
source: &FileLock<FE>
) -> Result<FileLock<FE>, Error>where
FE: Clone,
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.
sourcepub fn delete<'a, Q>(
&'a mut self,
name: &'a Q
) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>
pub fn delete<'a, Q>( &'a mut self, name: &'a Q ) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>
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.
sourcepub fn sync(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>where
FE: for<'a> FileSave<'a>,
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.
sourcepub fn truncate<'a>(
&'a mut self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>
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
.
Trait Implementations§
Auto Trait Implementations§
impl<FE> !RefUnwindSafe for Dir<FE>
impl<FE> Send for Dir<FE>
impl<FE> Sync for Dir<FE>
impl<FE> Unpin for Dir<FE>
impl<FE> !UnwindSafe for Dir<FE>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<F> Match for F
impl<F> Match for F
source§fn matches<T>(&self) -> boolwhere
T: TryCastFrom<Self>,
fn matches<T>(&self) -> boolwhere
T: TryCastFrom<Self>,
true
if self
can be cast into the target type T
.source§impl<F, T> TryCastFrom<F> for Twhere
T: CastFrom<F>,
impl<F, T> TryCastFrom<F> for Twhere
T: CastFrom<F>,
source§fn can_cast_from(_: &F) -> bool
fn can_cast_from(_: &F) -> bool
value
can be cast into Self
.source§fn opt_cast_from(f: F) -> Option<T>
fn opt_cast_from(f: F) -> Option<T>
Some(Self)
if the source value can be cast into Self
, otherwise None
.source§impl<F, T> TryCastInto<T> for Fwhere
T: TryCastFrom<F>,
impl<F, T> TryCastInto<T> for Fwhere
T: TryCastFrom<F>,
source§fn can_cast_into(&self) -> bool
fn can_cast_into(&self) -> bool
self
can be cast into T
.source§fn opt_cast_into(self) -> Option<T>
fn opt_cast_into(self) -> Option<T>
Some(T)
if self
can be cast into T
, otherwise None
.