Skip to content

Commit

Permalink
Remove some no-longer-necessary Ok-wrapping (#7205)
Browse files Browse the repository at this point in the history
Since #7152 the error types of sync and async are the same so much of
the prior `Ok`-wrapping isn't necessary any more.
  • Loading branch information
alexcrichton authored Oct 10, 2023
1 parent 4c34504 commit 1abac1e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 93 deletions.
104 changes: 38 additions & 66 deletions crates/wasi/src/preview2/host/filesystem/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
len: sync_filesystem::Filesize,
advice: sync_filesystem::Advice,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::advise(self, fd, offset, len, advice.into()).await
})?)
})
}

fn sync_data(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::sync_data(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::sync_data(self, fd).await })
}

fn get_flags(
Expand All @@ -55,9 +53,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
fd: Resource<sync_filesystem::Descriptor>,
size: sync_filesystem::Filesize,
) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::set_size(self, fd, size).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::set_size(self, fd, size).await })
}

fn set_times(
Expand All @@ -66,9 +62,9 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
atim: sync_filesystem::NewTimestamp,
mtim: sync_filesystem::NewTimestamp,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::set_times(self, fd, atim.into(), mtim.into()).await
})?)
})
}

fn read(
Expand All @@ -77,9 +73,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
len: sync_filesystem::Filesize,
offset: sync_filesystem::Filesize,
) -> FsResult<(Vec<u8>, bool)> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::read(self, fd, len, offset).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::read(self, fd, len, offset).await })
}

fn write(
Expand All @@ -88,34 +82,28 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
buf: Vec<u8>,
offset: sync_filesystem::Filesize,
) -> FsResult<sync_filesystem::Filesize> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::write(self, fd, buf, offset).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::write(self, fd, buf, offset).await })
}

fn read_directory(
&mut self,
fd: Resource<sync_filesystem::Descriptor>,
) -> FsResult<Resource<sync_filesystem::DirectoryEntryStream>> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::read_directory(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::read_directory(self, fd).await })
}

fn sync(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::sync(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::sync(self, fd).await })
}

fn create_directory_at(
&mut self,
fd: Resource<sync_filesystem::Descriptor>,
path: String,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::create_directory_at(self, fd, path).await
})?)
})
}

fn stat(
Expand Down Expand Up @@ -145,7 +133,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
atim: sync_filesystem::NewTimestamp,
mtim: sync_filesystem::NewTimestamp,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::set_times_at(
self,
fd,
Expand All @@ -155,7 +143,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
mtim.into(),
)
.await
})?)
})
}

fn link_at(
Expand All @@ -167,7 +155,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
new_descriptor: Resource<sync_filesystem::Descriptor>,
new_path: String,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::link_at(
self,
fd,
Expand All @@ -177,7 +165,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
new_path,
)
.await
})?)
})
}

fn open_at(
Expand All @@ -189,7 +177,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
flags: sync_filesystem::DescriptorFlags,
mode: sync_filesystem::Modes,
) -> FsResult<Resource<sync_filesystem::Descriptor>> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::open_at(
self,
fd,
Expand All @@ -200,7 +188,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
mode.into(),
)
.await
})?)
})
}

fn drop(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> anyhow::Result<()> {
Expand All @@ -212,19 +200,17 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
fd: Resource<sync_filesystem::Descriptor>,
path: String,
) -> FsResult<String> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::readlink_at(self, fd, path).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::readlink_at(self, fd, path).await })
}

fn remove_directory_at(
&mut self,
fd: Resource<sync_filesystem::Descriptor>,
path: String,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::remove_directory_at(self, fd, path).await
})?)
})
}

fn rename_at(
Expand All @@ -234,9 +220,9 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
new_fd: Resource<sync_filesystem::Descriptor>,
new_path: String,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::rename_at(self, fd, old_path, new_fd, new_path).await
})?)
})
}

fn symlink_at(
Expand All @@ -245,19 +231,17 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
src_path: String,
dest_path: String,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::symlink_at(self, fd, src_path, dest_path).await
})?)
})
}

fn unlink_file_at(
&mut self,
fd: Resource<sync_filesystem::Descriptor>,
path: String,
) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::unlink_file_at(self, fd, path).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::unlink_file_at(self, fd, path).await })
}

fn access_at(
Expand All @@ -267,7 +251,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
path: String,
access: sync_filesystem::AccessType,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::access_at(
self,
fd,
Expand All @@ -276,7 +260,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
access.into(),
)
.await
})?)
})
}

fn change_file_permissions_at(
Expand All @@ -286,7 +270,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
path: String,
mode: sync_filesystem::Modes,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::change_file_permissions_at(
self,
fd,
Expand All @@ -295,7 +279,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
mode.into(),
)
.await
})?)
})
}

fn change_directory_permissions_at(
Expand All @@ -305,7 +289,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
path: String,
mode: sync_filesystem::Modes,
) -> FsResult<()> {
Ok(in_tokio(async {
in_tokio(async {
async_filesystem::HostDescriptor::change_directory_permissions_at(
self,
fd,
Expand All @@ -314,37 +298,27 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
mode.into(),
)
.await
})?)
})
}

fn lock_shared(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::lock_shared(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::lock_shared(self, fd).await })
}

fn lock_exclusive(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::lock_exclusive(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::lock_exclusive(self, fd).await })
}

fn try_lock_shared(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::try_lock_shared(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::try_lock_shared(self, fd).await })
}

fn try_lock_exclusive(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::try_lock_exclusive(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::try_lock_exclusive(self, fd).await })
}

fn unlock(&mut self, fd: Resource<sync_filesystem::Descriptor>) -> FsResult<()> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::unlock(self, fd).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::unlock(self, fd).await })
}

fn read_via_stream(
Expand Down Expand Up @@ -381,9 +355,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
a: Resource<sync_filesystem::Descriptor>,
b: Resource<sync_filesystem::Descriptor>,
) -> anyhow::Result<bool> {
Ok(in_tokio(async {
async_filesystem::HostDescriptor::is_same_object(self, a, b).await
})?)
in_tokio(async { async_filesystem::HostDescriptor::is_same_object(self, a, b).await })
}
fn metadata_hash(
&mut self,
Expand Down
Loading

0 comments on commit 1abac1e

Please sign in to comment.