pub struct Dir<FE> { /* private fields */ }
Expand description
A filesystem directory
Implementations§
source§impl<FE: FileLoad> Dir<FE>
impl<FE: FileLoad> Dir<FE>
sourcepub fn contains<N: Borrow<str>>(&self, name: N) -> bool
pub fn contains<N: Borrow<str>>(&self, name: N) -> 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 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: Eq + Hash + ?Sized>(&self, name: &Q) -> Option<&DirEntry<FE>>where
String: Borrow<Q>,
pub fn get<Q: Eq + Hash + ?Sized>(&self, name: &Q) -> Option<&DirEntry<FE>>where
String: Borrow<Q>,
Get the entry with the given name
from this Dir
.
sourcepub fn get_dir<Q: Eq + Hash + ?Sized>(&self, name: &Q) -> Option<&DirLock<FE>>where
String: Borrow<Q>,
pub fn get_dir<Q: Eq + Hash + ?Sized>(&self, name: &Q) -> Option<&DirLock<FE>>where
String: Borrow<Q>,
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: Eq + Hash + ?Sized>(&self, name: &Q) -> Option<FileLock<FE>>where
String: Borrow<Q>,
pub fn get_file<Q: Eq + Hash + ?Sized>(&self, name: &Q) -> Option<FileLock<FE>>where
String: Borrow<Q>,
Get the file with the given name
from this Dir
, if present.
Also returns None
if the entry at name
is a directory.
source§impl<FE: FileLoad> Dir<FE>
impl<FE: FileLoad> 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 delete(
&mut self,
name: String
) -> Pin<Box<dyn Future<Output = bool> + Send + '_>>
pub fn delete(
&mut self,
name: String
) -> Pin<Box<dyn Future<Output = bool> + Send + '_>>
Delete the entry with the given name
from this Dir
.
Returns true
if there was an entry present.
References to sub-directories and files remain valid even after deleting their parent directory, so writing to a file after deleting its parent directory will re-create the directory on the filesystem, and sync’ing the parent directory will delete the file.
Make sure to call 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::delete_and_sync
.
sourcepub fn delete_and_sync(
&mut self,
name: String
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + '_>>
pub fn delete_and_sync(
&mut self,
name: String
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + '_>>
Delete the entry with the given name
from this Dir
and the filesystem.
Returns true
if there was an entry present.
sourcepub fn sync(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>
pub fn sync(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>
Synchronize the contents of this directory with the filesystem.
This will create new subdirectories and delete entries from the filesystem, but will NOT synchronize the contents of any child directories or files.
Trait Implementations§
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<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
.