diff --git a/crates/wasi-common/src/fs/dir.rs b/crates/wasi-common/src/fs/dir.rs index 5c23296699..d07734f657 100644 --- a/crates/wasi-common/src/fs/dir.rs +++ b/crates/wasi-common/src/fs/dir.rs @@ -1,5 +1,4 @@ -use crate::fs::{File, OpenOptions, ReadDir}; -use crate::wasi::types; +use crate::fs::{Fd, File, OpenOptions, ReadDir}; use crate::wasi::wasi_snapshot_preview1::WasiSnapshotPreview1; use crate::WasiCtx; #[cfg(unix)] @@ -18,12 +17,12 @@ use std::{io, path::Path}; /// don't interoperate well with the capability-oriented security model. pub struct Dir<'ctx> { ctx: &'ctx WasiCtx, - fd: types::Fd, + fd: Fd, } impl<'ctx> Dir<'ctx> { /// Constructs a new instance of `Self` from the given raw WASI file descriptor. - pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: types::Fd) -> Self { + pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: Fd) -> Self { Self { ctx, fd } } @@ -39,7 +38,7 @@ impl<'ctx> Dir<'ctx> { /// [`std::fs::File::open`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.open pub fn open_file>(&mut self, path: P) -> io::Result { let path = path.as_ref(); - let mut fd = types::Fd::from(0); + let mut fd = Fd::from(0); // TODO: Refactor the hostcalls functions to split out the encoding/decoding // parts from the underlying functionality, so that we can call into the @@ -92,7 +91,7 @@ impl<'ctx> Dir<'ctx> { /// TODO: Not yet implemented. See the comment in `open_file`. pub fn open_dir>(&mut self, path: P) -> io::Result { let path = path.as_ref(); - let mut fd = types::Fd::from(0); + let mut fd = Fd::from(0); // TODO: See the comment in `open_file`. unimplemented!("Dir::open_dir"); @@ -124,7 +123,7 @@ impl<'ctx> Dir<'ctx> { /// [`std::fs::File::create`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.create pub fn create_file>(&mut self, path: P) -> io::Result { let path = path.as_ref(); - let mut fd = types::Fd::from(0); + let mut fd = Fd::from(0); // TODO: See the comments in `open_file`. // diff --git a/crates/wasi-common/src/fs/file.rs b/crates/wasi-common/src/fs/file.rs index 39a3b5a274..be720a3c5f 100644 --- a/crates/wasi-common/src/fs/file.rs +++ b/crates/wasi-common/src/fs/file.rs @@ -1,5 +1,4 @@ -use crate::fs::Metadata; -use crate::wasi::types; +use crate::fs::{Fd, Metadata}; use crate::wasi::wasi_snapshot_preview1::WasiSnapshotPreview1; use crate::Result; use crate::WasiCtx; @@ -19,7 +18,7 @@ use std::io; /// [`Dir::create_file`]: struct.Dir.html#method.create_file pub struct File<'ctx> { ctx: &'ctx WasiCtx, - fd: types::Fd, + fd: Fd, } impl<'ctx> File<'ctx> { @@ -28,7 +27,7 @@ impl<'ctx> File<'ctx> { /// This corresponds to [`std::fs::File::from_raw_fd`]. /// /// [`std::fs::File::from_raw_fd`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.from_raw_fd - pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: types::Fd) -> Self { + pub unsafe fn from_raw_wasi_fd(ctx: &'ctx WasiCtx, fd: Fd) -> Self { Self { ctx, fd } } @@ -89,7 +88,7 @@ impl<'ctx> io::Read for File<'ctx> { /// TODO: Not yet implemented. See the comment in `Dir::open_file`. fn read(&mut self, buf: &mut [u8]) -> io::Result { // TODO - // let iov = [types::Iovec { + // let iov = [Iovec { // buf: buf.as_mut_ptr() as *mut u8, // buf_len: buf.len(), // }]; diff --git a/crates/wasi-common/src/fs/mod.rs b/crates/wasi-common/src/fs/mod.rs index c406581431..213d5bf234 100644 --- a/crates/wasi-common/src/fs/mod.rs +++ b/crates/wasi-common/src/fs/mod.rs @@ -39,6 +39,8 @@ mod open_options; mod permissions; mod readdir; +pub use crate::wasi::types::Fd; + pub use dir::*; pub use dir_builder::*; pub use dir_entry::*; diff --git a/crates/wasi-common/src/fs/readdir.rs b/crates/wasi-common/src/fs/readdir.rs index 1e9ec229aa..b3b3c4969c 100644 --- a/crates/wasi-common/src/fs/readdir.rs +++ b/crates/wasi-common/src/fs/readdir.rs @@ -1,5 +1,4 @@ -use crate::fs::DirEntry; -use crate::wasi::types; +use crate::fs::{DirEntry, Fd}; /// Iterator over the entries in a directory. /// @@ -9,12 +8,12 @@ use crate::wasi::types; /// /// [`std::fs::ReadDir`]: https://doc.rust-lang.org/std/fs/struct.ReadDir.html pub struct ReadDir { - fd: types::Fd, + fd: Fd, } impl ReadDir { /// Constructs a new instance of `Self` from the given raw WASI file descriptor. - pub unsafe fn from_raw_wasi_fd(fd: types::Fd) -> Self { + pub unsafe fn from_raw_wasi_fd(fd: Fd) -> Self { Self { fd } } }