Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dir-structure-tools/tests/async_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ async fn deferred_read_or_own_write_to_async_ref() {
assert_eq!(fs::read_to_string(d.join("out2.txt")).unwrap(), "f2");
}

/// `()` writes as a no-op through `WriteToAsyncRef`, so `DirChildren<(), _>` can be
/// used as a placeholder entry type that satisfies the write bound without real data.
#[tokio::test]
async fn unit_write_to_async_ref_is_no_op() {
use dir_structure::traits::vfs::VfsCore;
use dir_structure_tools::NoFilter;

let vfs = TokioFsVfs;

let p = test_dir("unit_write_to_async_ref_is_no_op");
().write_to_async_ref(p.join("noop.txt"), Pin::new(&vfs))
.await
.unwrap();
assert!(!p.join("noop.txt").exists());

let skeleton: DirChildren<(), NoFilter, <TokioFsVfs as VfsCore>::Path> = DirChildren::default();
skeleton
.write_to_async_ref(p.join("dir"), Pin::new(&vfs))
.await
.unwrap();
}

#[tokio::test]
async fn read_all_directory_files() {
#[derive(dir_structure::DirStructureAsync)]
Expand Down
22 changes: 22 additions & 0 deletions dir-structure/src/traits/asy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,25 @@ impl<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> WriteToAsync<'a, Vfs> for (
future::ready(Ok(()))
}
}

#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
impl<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> WriteToAsyncRef<'a, Vfs> for () {
type Future<'b>
= future::Ready<VfsResult<(), Vfs>>
where
Self: 'b,
'a: 'b,
Vfs: 'b;

fn write_to_async_ref<'b>(
&'b self,
_path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
_vfs: Pin<&'b Vfs>,
) -> Self::Future<'b>
where
'a: 'b,
{
future::ready(Ok(()))
}
}
Loading