Skip to content

Commit

Permalink
Added wasm32 part for vfs file access
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed May 3, 2022
1 parent 1f3613c commit 0d6e13a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/vfs/src/host_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::fs;
use std::io::{self, Read, Seek, Write};
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(target_arch = "wasm32")]
use std::os::wasi::io::{AsRawFd, RawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawHandle, RawHandle};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -67,6 +69,31 @@ impl TryInto<RawHandle> for FileDescriptor {
}
}

#[cfg(target_arch = "wasm32")]
impl<T> TryIntoFileDescriptor for T
where
T: AsRawFd,
{
type Error = FsError;

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

#[cfg(target_arch = "wasm32")]
impl TryInto<RawFd> for FileDescriptor {
type Error = FsError;

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

#[derive(Debug, Default, Clone)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct FileSystem;
Expand Down

0 comments on commit 0d6e13a

Please sign in to comment.