Struct hoard::hoard_item::CachedHoardItem
source · pub struct CachedHoardItem { /* private fields */ }
Expand description
Wrapper around HoardItem
that accesses the filesystem at creation time and
caches file data.
Usage
This does nothing to ensure that files are not modified during its lifetime. For directly
interacting with files on the filesystem, HoardItem
may be better.
This struct is useful for prolonged processing of a given file.
Implementations§
source§impl CachedHoardItem
impl CachedHoardItem
sourcepub async fn new(
pile_name: PileName,
hoard_prefix: HoardPath,
system_prefix: SystemPath,
relative_path: RelativePath
) -> Result<Self>
pub async fn new( pile_name: PileName, hoard_prefix: HoardPath, system_prefix: SystemPath, relative_path: RelativePath ) -> Result<Self>
Create a new CachedHoardItem
.
See HoardItem::new
for more about usage.
Errors
Will return I/O errors if they occur while processing file data, with the exception of
NotFound
errors, which are translated into None
values, as applicable.
sourcepub async fn try_from_hoard_item(inner: HoardItem) -> Result<Self>
pub async fn try_from_hoard_item(inner: HoardItem) -> Result<Self>
sourcepub fn pile_name(&self) -> &PileName
pub fn pile_name(&self) -> &PileName
Returns the name of the pile this item belongs to, if any.
sourcepub fn relative_path(&self) -> &RelativePath
pub fn relative_path(&self) -> &RelativePath
Returns the relative path for this item.
sourcepub fn hoard_prefix(&self) -> &HoardPath
pub fn hoard_prefix(&self) -> &HoardPath
Returns the hoard-controlled path for this item’s pile.
sourcepub fn system_prefix(&self) -> &SystemPath
pub fn system_prefix(&self) -> &SystemPath
Returns the system path for this item’s pile.
sourcepub fn hoard_path(&self) -> &HoardPath
pub fn hoard_path(&self) -> &HoardPath
Returns the Hoard-controlled path for this item.
If HoardItem::relative_path()
is None
, this is the same as
HoardItem::hoard_prefix()
.
sourcepub fn system_path(&self) -> &SystemPath
pub fn system_path(&self) -> &SystemPath
Returns the system path for this item.
If HoardItem::relative_path()
is None
, this is the same as
HoardItem::system_prefix()
.
sourcepub fn is_file(&self) -> bool
pub fn is_file(&self) -> bool
Returns whether this item is a file.
This is true
if:
- At least one of
hoard_path
orsystem_path
exists - All existing paths are a file
sourcepub fn is_dir(&self) -> bool
pub fn is_dir(&self) -> bool
Returns whether this item is a directory.
This is true
if:
- At least one of
hoard_path
orsystem_path
exists - All existing paths are directories
sourcepub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Returns whether this file contains text.
This is true
if at least one file (system/hoard) exists and all files that exist contain
text.
sourcepub fn is_binary(&self) -> bool
pub fn is_binary(&self) -> bool
Returns whether this file does not contains text.
This is true
if at least one file (system/hoard) exists and is not text.
sourcepub fn diff(&self) -> Option<&Diff>
pub fn diff(&self) -> Option<&Diff>
Returns the precomputed diff between the hoard and system files of this CachedHoardItem
.
sourcepub fn hoard_checksum(&self, typ: ChecksumType) -> Option<Checksum>
pub fn hoard_checksum(&self, typ: ChecksumType) -> Option<Checksum>
Returns the requested ChecksumType
for the Hoard version of the file.
Errors
Returns Ok(None)
if the file does not exist, and errors for all other
error cases for std::fs::read
, including if hoard_path
is a directory.
If always calling this function with a constant or programmer-determined value,
consider using CachedHoardItem::hoard_md5
or CachedHoardItem::hoard_sha256
instead.
sourcepub fn hoard_md5(&self) -> Option<Checksum>
pub fn hoard_md5(&self) -> Option<Checksum>
Returns the MD5 checksum for the Hoard version of the file.
Errors
Returns Ok(None)
if the file does not exist, and errors for all other
error cases for std::fs::read
, including if hoard_path
is a directory.
sourcepub fn hoard_sha256(&self) -> Option<Checksum>
pub fn hoard_sha256(&self) -> Option<Checksum>
Returns the SHA256 checksum for the Hoard version of the file.
Errors
Returns Ok(None)
if the file does not exist, and errors for all other
error cases for std::fs::read
, including if hoard_path
is a directory.
sourcepub fn system_checksum(&self, typ: ChecksumType) -> Option<Checksum>
pub fn system_checksum(&self, typ: ChecksumType) -> Option<Checksum>
Returns the requested ChecksumType
for the system version of the file.
Errors
Returns Ok(None)
if the file does not exist, and errors for all other
error cases for std::fs::read
, including if system_path
is a directory.
If always calling this function with a constant or programmer-determined value,
consider using CachedHoardItem::system_md5
or CachedHoardItem::system_sha256
instead.
sourcepub fn system_md5(&self) -> Option<Checksum>
pub fn system_md5(&self) -> Option<Checksum>
Returns the MD5 checksum for the system version of the file.
Errors
Returns Ok(None)
if the file does not exist, and errors for all other
error cases for std::fs::read
, including if system_path
is a directory.
sourcepub fn system_sha256(&self) -> Option<Checksum>
pub fn system_sha256(&self) -> Option<Checksum>
Returns the SHA256 checksum for the system version of the file.
Errors
Returns Ok(None)
if the file does not exist, and errors for all other
error cases for std::fs::read
, including if system_path
is a directory.
Trait Implementations§
source§impl Clone for CachedHoardItem
impl Clone for CachedHoardItem
source§fn clone(&self) -> CachedHoardItem
fn clone(&self) -> CachedHoardItem
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CachedHoardItem
impl Debug for CachedHoardItem
source§impl From<CachedHoardItem> for HoardItem
impl From<CachedHoardItem> for HoardItem
source§fn from(cached: CachedHoardItem) -> Self
fn from(cached: CachedHoardItem) -> Self
source§impl Hash for CachedHoardItem
impl Hash for CachedHoardItem
source§impl Ord for CachedHoardItem
impl Ord for CachedHoardItem
source§fn cmp(&self, other: &CachedHoardItem) -> Ordering
fn cmp(&self, other: &CachedHoardItem) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq for CachedHoardItem
impl PartialEq for CachedHoardItem
source§fn eq(&self, other: &CachedHoardItem) -> bool
fn eq(&self, other: &CachedHoardItem) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for CachedHoardItem
impl PartialOrd for CachedHoardItem
source§fn partial_cmp(&self, other: &CachedHoardItem) -> Option<Ordering>
fn partial_cmp(&self, other: &CachedHoardItem) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for CachedHoardItem
impl StructuralEq for CachedHoardItem
impl StructuralPartialEq for CachedHoardItem
Auto Trait Implementations§
impl RefUnwindSafe for CachedHoardItem
impl Send for CachedHoardItem
impl Sync for CachedHoardItem
impl Unpin for CachedHoardItem
impl UnwindSafe for CachedHoardItem
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
self
, then passes self.as_mut()
into the pipe
function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds.