Skip to content

Commit

Permalink
fix(vfs) Change FileDescriptor to be unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Aug 17, 2021
1 parent 9e6c07d commit ff9c7f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 11 additions & 13 deletions lib/vfs/src/host_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ where
type Error = FsError;

fn try_into_filedescriptor(&self) -> std::result::Result<FileDescriptor, Self::Error> {
Ok(FileDescriptor {
inner: self
.as_raw_fd()
Ok(FileDescriptor(
self.as_raw_fd()
.try_into()
.map_err(|_| FsError::InvalidFd)?,
})
))
}
}

Expand All @@ -43,7 +42,7 @@ impl TryInto<RawFd> for FileDescriptor {
type Error = FsError;

fn try_into(self) -> std::result::Result<RawFd, Self::Error> {
self.inner.try_into().map_err(|_| FsError::InvalidFd)
self.0.try_into().map_err(|_| FsError::InvalidFd)
}
}

Expand All @@ -55,12 +54,11 @@ where
type Error = FsError;

fn try_into_filedescriptor(&self) -> Result<FileDescriptor, Self::Error> {
Ok(FileDescriptor {
inner: self
.as_raw_handle()
Ok(FileDescriptor(
self.as_raw_handle()
.try_into()
.map_err(|_| FsError::InvalidFd)?,
})
))
}
}

Expand All @@ -69,7 +67,7 @@ impl TryInto<RawHandle> for FileDescriptor {
type Error = FsError;

fn try_into(self) -> std::result::Result<RawHandle, Self::Error> {
self.inner.try_into().map_err(|_| FsError::InvalidFd)
self.0.try_into().map_err(|_| FsError::InvalidFd)
}
}

Expand Down Expand Up @@ -210,7 +208,7 @@ pub struct File {

#[cfg(feature = "enable-serde")]
impl<'de> Deserialize<'de> for File {
fn deserialize<D>(deserializer: D) -> Result<File, D::Error>
fn deserialize<D>(deserializer: D) -> std::result::Result<File, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand All @@ -230,7 +228,7 @@ impl<'de> Deserialize<'de> for File {
formatter.write_str("struct File")
}

fn visit_seq<V>(self, mut seq: V) -> Result<Self::Value, V::Error>
fn visit_seq<V>(self, mut seq: V) -> std::result::Result<Self::Value, V::Error>
where
V: de::SeqAccess<'de>,
{
Expand All @@ -253,7 +251,7 @@ impl<'de> Deserialize<'de> for File {
})
}

fn visit_map<V>(self, mut map: V) -> Result<Self::Value, V::Error>
fn visit_map<V>(self, mut map: V) -> std::result::Result<Self::Value, V::Error>
where
V: de::MapAccess<'de>,
{
Expand Down
4 changes: 1 addition & 3 deletions lib/vfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ pub mod mem_fs;
pub type Result<T> = std::result::Result<T, FsError>;

#[repr(transparent)]
pub struct FileDescriptor {
inner: usize,
}
pub struct FileDescriptor(usize);

pub trait FileSystem: fmt::Debug + Send + Sync + 'static {
fn read_dir(&self, path: &Path) -> Result<ReadDir>;
Expand Down

0 comments on commit ff9c7f1

Please sign in to comment.