pub struct DeferredRead<'a, T, Vfs: VfsCore = FsVfs, const CHECK_ON_READ: bool = false>(pub <<Vfs as VfsCore>::Path as PathType>::OwnedPath, _, _);Expand description
A wrapper that defers the reading of a file until it is actually needed.
The only thing you can do with a DeferredRead is to call DeferredRead::perform_read,
which will read the file and return the value.
See the DeferredRead::perform_read method for more details.
For a version that also caches the read value, see DeferredReadOrOwn.
Tuple Fields§
§0: <<Vfs as VfsCore>::Path as PathType>::OwnedPathImplementations§
Source§impl<'a, const CHECK_ON_READ: bool, T, Vfs: Vfs<'a, Path = P>, P: PathType + ?Sized + 'a> DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: ReadFrom<'a, Vfs>,
impl<'a, const CHECK_ON_READ: bool, T, Vfs: Vfs<'a, Path = P>, P: PathType + ?Sized + 'a> DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: ReadFrom<'a, Vfs>,
Sourcepub fn perform_read(&self) -> VfsResult<T, Vfs>
pub fn perform_read(&self) -> VfsResult<T, Vfs>
Performs the read and returns the value.
If the value changed on disk since the DeferredRead was created, then the
new value will be read from disk and returned.
For a cached version see DeferredReadOrOwn.
§Examples
use std::path::Path;
use std::pin::Pin;
use dir_structure::traits::sync::DirStructureItem;
use dir_structure::deferred_read::DeferredRead;
use dir_structure::prelude::*;
#[derive(dir_structure::DirStructure)]
struct Dir<'vfs, Vfs: VfsCore> {
#[dir_structure(path = "f.txt")]
f: DeferredRead<'vfs, String, Vfs>,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let d = Path::new("dir");
std::fs::create_dir_all(&d)?;
std::fs::write(d.join("f.txt"), "Hello, world!")?;
let dir = Dir::read(&d)?;
assert_eq!(dir.f.perform_read()?, "Hello, world!");
std::fs::write(d.join("f.txt"), "Goodbye, world!")?;
assert_eq!(dir.f.perform_read()?, "Goodbye, world!");
Ok(())
}Source§impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsAsync<Path = P> + 'a, P: PathType + ?Sized + 'a> DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: ReadFromAsync<'a, Vfs> + Send + 'static,
impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsAsync<Path = P> + 'a, P: PathType + ?Sized + 'a> DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: ReadFromAsync<'a, Vfs> + Send + 'static,
Sourcepub async fn perform_read_async(&self) -> VfsResult<T, Vfs>
Available on crate feature async only.
pub async fn perform_read_async(&self) -> VfsResult<T, Vfs>
async only.Performs the read asynchronously and returns the value.
If the value changed on disk since the DeferredRead was created, then the
new value will be read from disk and returned.
For a cached version see DeferredReadOrOwn.
Asynchronous version of DeferredRead::perform_read.
Trait Implementations§
Source§impl<'a, T, Vfs: VfsCore, const CHECK_ON_READ: bool> AssertEq for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, T, Vfs: VfsCore, const CHECK_ON_READ: bool> AssertEq for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
Source§impl<'a, T: Clone, Vfs: Clone + VfsCore, const CHECK_ON_READ: bool> Clone for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, T: Clone, Vfs: Clone + VfsCore, const CHECK_ON_READ: bool> Clone for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
Source§fn clone(&self) -> DeferredRead<'a, T, Vfs, CHECK_ON_READ>
fn clone(&self) -> DeferredRead<'a, T, Vfs, CHECK_ON_READ>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsCore<Path = P>, P> Debug for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsCore<Path = P>, P> Debug for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
Source§impl<const CHECK_ON_READ: bool, T, Vfs: VfsCore> DynamicHasField for DeferredRead<'_, T, Vfs, CHECK_ON_READ>where
T: DynamicHasField,
Available on crate feature resolve-path only.
impl<const CHECK_ON_READ: bool, T, Vfs: VfsCore> DynamicHasField for DeferredRead<'_, T, Vfs, CHECK_ON_READ>where
T: DynamicHasField,
resolve-path only.Source§type Inner = <T as DynamicHasField>::Inner
type Inner = <T as DynamicHasField>::Inner
Source§fn resolve_path<P: OwnedPathType>(p: P, name: &str) -> P
fn resolve_path<P: OwnedPathType>(p: P, name: &str) -> P
Self, given the name
passed into the resolve_path! macro.Source§impl<const CHECK_ON_READ: bool, const NAME: [char; 32], T, Vfs: VfsCore> HasField<NAME> for DeferredRead<'_, T, Vfs, CHECK_ON_READ>where
T: HasField<NAME>,
Available on crate feature resolve-path only.
impl<const CHECK_ON_READ: bool, const NAME: [char; 32], T, Vfs: VfsCore> HasField<NAME> for DeferredRead<'_, T, Vfs, CHECK_ON_READ>where
T: HasField<NAME>,
resolve-path only.Source§fn resolve_path<P: OwnedPathType>(p: P) -> P
fn resolve_path<P: OwnedPathType>(p: P) -> P
Self.Source§impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsCore> Hash for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsCore> Hash for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
Source§impl<'a, const CHECK_ON_READ: bool, T, Vfs: Vfs<'a>> ReadFrom<'a, Vfs> for DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: ReadFrom<'a, Vfs>,
impl<'a, const CHECK_ON_READ: bool, T, Vfs: Vfs<'a>> ReadFrom<'a, Vfs> for DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: ReadFrom<'a, Vfs>,
Source§impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsAsync<Path = P> + 'static, P: PathType + ?Sized + 'a> ReadFromAsync<'a, Vfs> for DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: Send + ReadFromAsync<'a, Vfs> + 'static,
Available on crate feature async only.
impl<'a, const CHECK_ON_READ: bool, T, Vfs: VfsAsync<Path = P> + 'static, P: PathType + ?Sized + 'a> ReadFromAsync<'a, Vfs> for DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
T: Send + ReadFromAsync<'a, Vfs> + 'static,
async only.Source§impl<'a, 't, const CHECK_ON_READ: bool, T, P: PathType + ?Sized + 'a, SelfVfs: Vfs<'a, Path = P>, TargetVfs: WriteSupportingVfs<'t, Path = P>> WriteTo<'t, TargetVfs> for DeferredRead<'a, T, SelfVfs, CHECK_ON_READ>
impl<'a, 't, const CHECK_ON_READ: bool, T, P: PathType + ?Sized + 'a, SelfVfs: Vfs<'a, Path = P>, TargetVfs: WriteSupportingVfs<'t, Path = P>> WriteTo<'t, TargetVfs> for DeferredRead<'a, T, SelfVfs, CHECK_ON_READ>
Source§impl<'f, const CHECK_ON_READ: bool, T, P: PathType + ?Sized + 'f, SelfVfs: VfsAsync<Path = P> + 'f, TargetVfs: WriteSupportingVfsAsync<Path = P> + 'f> WriteToAsync<'f, TargetVfs> for DeferredRead<'f, T, SelfVfs, CHECK_ON_READ>where
T: for<'a> ReadFromAsync<'a, SelfVfs> + for<'a> WriteToAsync<'a, TargetVfs> + Send + 'static,
for<'a> <T as ReadFromAsync<'a, SelfVfs>>::Future: Future<Output = VfsResult<T, SelfVfs>> + Unpin + 'a,
for<'a> <T as WriteToAsync<'a, TargetVfs>>::Future: Future<Output = VfsResult<(), TargetVfs>> + Unpin + 'a,
Available on crate feature async only.
impl<'f, const CHECK_ON_READ: bool, T, P: PathType + ?Sized + 'f, SelfVfs: VfsAsync<Path = P> + 'f, TargetVfs: WriteSupportingVfsAsync<Path = P> + 'f> WriteToAsync<'f, TargetVfs> for DeferredRead<'f, T, SelfVfs, CHECK_ON_READ>where
T: for<'a> ReadFromAsync<'a, SelfVfs> + for<'a> WriteToAsync<'a, TargetVfs> + Send + 'static,
for<'a> <T as ReadFromAsync<'a, SelfVfs>>::Future: Future<Output = VfsResult<T, SelfVfs>> + Unpin + 'a,
for<'a> <T as WriteToAsync<'a, TargetVfs>>::Future: Future<Output = VfsResult<(), TargetVfs>> + Unpin + 'a,
async only.Source§type Future = DeferredReadWriteFuture<'f, T, P, SelfVfs, TargetVfs>
type Future = DeferredReadWriteFuture<'f, T, P, SelfVfs, TargetVfs>
Source§fn write_to_async(
self,
path: P::OwnedPath,
vfs: Pin<&'f TargetVfs>,
) -> Self::Future
fn write_to_async( self, path: P::OwnedPath, vfs: Pin<&'f TargetVfs>, ) -> Self::Future
Source§impl<'f, const CHECK_ON_READ: bool, T, P: PathType + ?Sized + 'f, SelfVfs: VfsAsync<Path = P> + 'f, TargetVfs: WriteSupportingVfsAsync<Path = P> + 'f> WriteToAsyncRef<'f, TargetVfs> for DeferredRead<'f, T, SelfVfs, CHECK_ON_READ>where
for<'a> T: ReadFromAsync<'a, SelfVfs> + WriteToAsync<'a, TargetVfs> + Send + 'a,
for<'a> <T as ReadFromAsync<'a, SelfVfs>>::Future: Future<Output = VfsResult<T, SelfVfs>> + Unpin + 'a,
for<'a> <T as WriteToAsync<'a, TargetVfs>>::Future: Future<Output = VfsResult<(), TargetVfs>> + Unpin + 'a,
Available on crate feature async only.
impl<'f, const CHECK_ON_READ: bool, T, P: PathType + ?Sized + 'f, SelfVfs: VfsAsync<Path = P> + 'f, TargetVfs: WriteSupportingVfsAsync<Path = P> + 'f> WriteToAsyncRef<'f, TargetVfs> for DeferredRead<'f, T, SelfVfs, CHECK_ON_READ>where
for<'a> T: ReadFromAsync<'a, SelfVfs> + WriteToAsync<'a, TargetVfs> + Send + 'a,
for<'a> <T as ReadFromAsync<'a, SelfVfs>>::Future: Future<Output = VfsResult<T, SelfVfs>> + Unpin + 'a,
for<'a> <T as WriteToAsync<'a, TargetVfs>>::Future: Future<Output = VfsResult<(), TargetVfs>> + Unpin + 'a,
async only.Source§type Future<'a> = DeferredReadWriteFuture<'a, T, P, SelfVfs, TargetVfs>
where
Self: 'a,
'f: 'a
type Future<'a> = DeferredReadWriteFuture<'a, T, P, SelfVfs, TargetVfs> where Self: 'a, 'f: 'a
Source§fn write_to_async_ref<'a>(
&'a self,
path: P::OwnedPath,
vfs: Pin<&'a TargetVfs>,
) -> Self::Future<'a>where
'f: 'a,
fn write_to_async_ref<'a>(
&'a self,
path: P::OwnedPath,
vfs: Pin<&'a TargetVfs>,
) -> Self::Future<'a>where
'f: 'a,
Auto Trait Implementations§
impl<'a, T, Vfs, const CHECK_ON_READ: bool> Freeze for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, T, Vfs, const CHECK_ON_READ: bool> RefUnwindSafe for DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
<<Vfs as VfsCore>::Path as PathType>::OwnedPath: RefUnwindSafe,
T: RefUnwindSafe,
Vfs: RefUnwindSafe,
impl<'a, T, Vfs, const CHECK_ON_READ: bool> Send for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, T, Vfs, const CHECK_ON_READ: bool> Sync for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, T, Vfs, const CHECK_ON_READ: bool> Unpin for DeferredRead<'a, T, Vfs, CHECK_ON_READ>
impl<'a, T, Vfs, const CHECK_ON_READ: bool> UnwindSafe for DeferredRead<'a, T, Vfs, CHECK_ON_READ>where
<<Vfs as VfsCore>::Path as PathType>::OwnedPath: UnwindSafe,
T: UnwindSafe,
Vfs: RefUnwindSafe,
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DirStructureItem for T
impl<T> DirStructureItem for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more