Trait wasi_common::file::WasiFile
source · pub trait WasiFile: Send + Sync {
Show 26 methods
fn as_any(&self) -> &dyn Any;
fn get_filetype<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<FileType, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait;
fn pollable(&self) -> Option<BorrowedFd<'_>> { ... }
fn isatty(&mut self) -> bool { ... }
fn sock_accept<'life0, 'async_trait>(
&'life0 mut self,
_fdflags: FdFlags
) -> Pin<Box<dyn Future<Output = Result<Box<dyn WasiFile>, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn sock_recv<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ri_data: &'life1 mut [IoSliceMut<'a>],
_ri_flags: RiFlags
) -> Pin<Box<dyn Future<Output = Result<(u64, RoFlags), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
{ ... }
fn sock_send<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_si_data: &'life1 [IoSlice<'a>],
_si_flags: SiFlags
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
{ ... }
fn sock_shutdown<'life0, 'async_trait>(
&'life0 mut self,
_how: SdFlags
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn datasync<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn sync<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn get_fdflags<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<FdFlags, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn set_fdflags<'life0, 'async_trait>(
&'life0 mut self,
_flags: FdFlags
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn get_filestat<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Filestat, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn set_filestat_size<'life0, 'async_trait>(
&'life0 mut self,
_size: u64
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn advise<'life0, 'async_trait>(
&'life0 mut self,
_offset: u64,
_len: u64,
_advice: Advice
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn allocate<'life0, 'async_trait>(
&'life0 mut self,
_offset: u64,
_len: u64
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn set_times<'life0, 'async_trait>(
&'life0 mut self,
_atime: Option<SystemTimeSpec>,
_mtime: Option<SystemTimeSpec>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn read_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 mut [IoSliceMut<'a>]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
{ ... }
fn read_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 mut [IoSliceMut<'a>],
_offset: u64
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
{ ... }
fn write_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 [IoSlice<'a>]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
{ ... }
fn write_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 [IoSlice<'a>],
_offset: u64
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
{ ... }
fn seek<'life0, 'async_trait>(
&'life0 mut self,
_pos: SeekFrom
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn peek<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
{ ... }
fn num_ready_bytes<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn readable<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
fn writable<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
{ ... }
}
Required Methods§
fn as_any(&self) -> &dyn Any
fn get_filetype<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<FileType, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Provided Methods§
fn pollable(&self) -> Option<BorrowedFd<'_>>
sourcefn isatty(&mut self) -> bool
fn isatty(&mut self) -> bool
Examples found in repository?
src/ctx.rs (line 109)
103 104 105 106 107 108 109 110 111 112 113 114
fn stdio_rights(f: &mut dyn WasiFile) -> FileCaps {
let mut rights = FileCaps::all();
// If `f` is a tty, restrict the `tell` and `seek` capabilities, so
// that wasi-libc's `isatty` correctly detects the file descriptor
// as a tty.
if f.isatty() {
rights &= !(FileCaps::TELL | FileCaps::SEEK);
}
rights
}
sourcefn sock_accept<'life0, 'async_trait>(
&'life0 mut self,
_fdflags: FdFlags
) -> Pin<Box<dyn Future<Output = Result<Box<dyn WasiFile>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sock_accept<'life0, 'async_trait>(
&'life0 mut self,
_fdflags: FdFlags
) -> Pin<Box<dyn Future<Output = Result<Box<dyn WasiFile>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 1050)
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
async fn sock_accept(
&mut self,
fd: types::Fd,
flags: types::Fdflags,
) -> Result<types::Fd, Error> {
let table = self.table();
let f = table
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::READ)?;
let file = f.sock_accept(FdFlags::from(flags)).await?;
let file_caps = FileCaps::READ
| FileCaps::WRITE
| FileCaps::FDSTAT_SET_FLAGS
| FileCaps::POLL_READWRITE
| FileCaps::FILESTAT_GET;
let fd = table.push(Box::new(FileEntry::new(file_caps, file)))?;
Ok(types::Fd::from(fd))
}
sourcefn sock_recv<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ri_data: &'life1 mut [IoSliceMut<'a>],
_ri_flags: RiFlags
) -> Pin<Box<dyn Future<Output = Result<(u64, RoFlags), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn sock_recv<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ri_data: &'life1 mut [IoSliceMut<'a>],
_ri_flags: RiFlags
) -> Pin<Box<dyn Future<Output = Result<(u64, RoFlags), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 1089)
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
async fn sock_recv<'a>(
&mut self,
fd: types::Fd,
ri_data: &types::IovecArray<'a>,
ri_flags: types::Riflags,
) -> Result<(types::Size, types::Roflags), Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::READ)?;
let mut guest_slices: Vec<wiggle::GuestSliceMut<u8>> =
ri_data
.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Iovec = iov_ptr.read()?;
Ok(iov.buf.as_array(iov.buf_len).as_slice_mut()?.expect(
"cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)",
))
})
.collect::<Result<_, Error>>()?;
let mut ioslices: Vec<IoSliceMut> = guest_slices
.iter_mut()
.map(|s| IoSliceMut::new(&mut *s))
.collect();
let (bytes_read, roflags) = f.sock_recv(&mut ioslices, RiFlags::from(ri_flags)).await?;
Ok((types::Size::try_from(bytes_read)?, roflags.into()))
}
sourcefn sock_send<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_si_data: &'life1 [IoSlice<'a>],
_si_flags: SiFlags
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn sock_send<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_si_data: &'life1 [IoSlice<'a>],
_si_flags: SiFlags
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 1121)
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
async fn sock_send<'a>(
&mut self,
fd: types::Fd,
si_data: &types::CiovecArray<'a>,
_si_flags: types::Siflags,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::WRITE)?;
let guest_slices: Vec<wiggle::GuestSlice<u8>> = si_data
.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Ciovec = iov_ptr.read()?;
Ok(iov
.buf
.as_array(iov.buf_len)
.as_slice()?
.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)"))
})
.collect::<Result<_, Error>>()?;
let ioslices: Vec<IoSlice> = guest_slices
.iter()
.map(|s| IoSlice::new(s.deref()))
.collect();
let bytes_written = f.sock_send(&ioslices, SiFlags::empty()).await?;
Ok(types::Size::try_from(bytes_written)?)
}
sourcefn sock_shutdown<'life0, 'async_trait>(
&'life0 mut self,
_how: SdFlags
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sock_shutdown<'life0, 'async_trait>(
&'life0 mut self,
_how: SdFlags
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
sourcefn datasync<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn datasync<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
sourcefn sync<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sync<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
sourcefn get_fdflags<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<FdFlags, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_fdflags<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<FdFlags, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
sourcefn set_fdflags<'life0, 'async_trait>(
&'life0 mut self,
_flags: FdFlags
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_fdflags<'life0, 'async_trait>(
&'life0 mut self,
_flags: FdFlags
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
sourcefn get_filestat<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Filestat, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_filestat<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Filestat, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 223)
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
async fn fd_filestat_get(&mut self, fd: types::Fd) -> Result<types::Filestat, Error> {
let table = self.table();
let fd = u32::from(fd);
if table.is::<FileEntry>(fd) {
let filestat = table
.get_file_mut(fd)?
.get_cap_mut(FileCaps::FILESTAT_GET)?
.get_filestat()
.await?;
Ok(filestat.into())
} else if table.is::<DirEntry>(fd) {
let filestat = table
.get_dir(fd)?
.get_cap(DirCaps::FILESTAT_GET)?
.get_filestat()
.await?;
Ok(filestat.into())
} else {
Err(Error::badf())
}
}
sourcefn set_filestat_size<'life0, 'async_trait>(
&'life0 mut self,
_size: u64
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_filestat_size<'life0, 'async_trait>(
&'life0 mut self,
_size: u64
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 246)
238 239 240 241 242 243 244 245 246 247 248 249
async fn fd_filestat_set_size(
&mut self,
fd: types::Fd,
size: types::Filesize,
) -> Result<(), Error> {
self.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::FILESTAT_SET_SIZE)?
.set_filestat_size(size)
.await?;
Ok(())
}
sourcefn advise<'life0, 'async_trait>(
&'life0 mut self,
_offset: u64,
_len: u64,
_advice: Advice
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn advise<'life0, 'async_trait>(
&'life0 mut self,
_offset: u64,
_len: u64,
_advice: Advice
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 112)
102 103 104 105 106 107 108 109 110 111 112 113 114 115
async fn fd_advise(
&mut self,
fd: types::Fd,
offset: types::Filesize,
len: types::Filesize,
advice: types::Advice,
) -> Result<(), Error> {
self.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::ADVISE)?
.advise(offset, len, advice.into())
.await?;
Ok(())
}
sourcefn allocate<'life0, 'async_trait>(
&'life0 mut self,
_offset: u64,
_len: u64
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn allocate<'life0, 'async_trait>(
&'life0 mut self,
_offset: u64,
_len: u64
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 126)
117 118 119 120 121 122 123 124 125 126 127 128 129
async fn fd_allocate(
&mut self,
fd: types::Fd,
offset: types::Filesize,
len: types::Filesize,
) -> Result<(), Error> {
self.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::ALLOCATE)?
.allocate(offset, len)
.await?;
Ok(())
}
sourcefn set_times<'life0, 'async_trait>(
&'life0 mut self,
_atime: Option<SystemTimeSpec>,
_mtime: Option<SystemTimeSpec>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_times<'life0, 'async_trait>(
&'life0 mut self,
_atime: Option<SystemTimeSpec>,
_mtime: Option<SystemTimeSpec>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 274)
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
async fn fd_filestat_set_times(
&mut self,
fd: types::Fd,
atim: types::Timestamp,
mtim: types::Timestamp,
fst_flags: types::Fstflags,
) -> Result<(), Error> {
let fd = u32::from(fd);
let table = self.table();
// Validate flags
let set_atim = fst_flags.contains(types::Fstflags::ATIM);
let set_atim_now = fst_flags.contains(types::Fstflags::ATIM_NOW);
let set_mtim = fst_flags.contains(types::Fstflags::MTIM);
let set_mtim_now = fst_flags.contains(types::Fstflags::MTIM_NOW);
let atim = systimespec(set_atim, atim, set_atim_now).map_err(|e| e.context("atim"))?;
let mtim = systimespec(set_mtim, mtim, set_mtim_now).map_err(|e| e.context("mtim"))?;
if table.is::<FileEntry>(fd) {
table
.get_file_mut(fd)
.expect("checked that entry is file")
.get_cap_mut(FileCaps::FILESTAT_SET_TIMES)?
.set_times(atim, mtim)
.await
} else if table.is::<DirEntry>(fd) {
table
.get_dir(fd)
.expect("checked that entry is dir")
.get_cap(DirCaps::FILESTAT_SET_TIMES)?
.set_times(".", atim, mtim, false)
.await
} else {
Err(Error::badf())
}
}
sourcefn read_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 mut [IoSliceMut<'a>]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 mut [IoSliceMut<'a>]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Examples found in repository?
src/snapshots/preview_0.rs (line 551)
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
async fn fd_read<'a>(
&mut self,
fd: types::Fd,
iovs: &types::IovecArray<'a>,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::READ)?;
let mut guest_slices: Vec<wiggle::GuestSliceMut<u8>> =
iovs.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Iovec = iov_ptr.read()?;
Ok(iov.buf.as_array(iov.buf_len).as_slice_mut()?.expect(
"cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)",
))
})
.collect::<Result<_, Error>>()?;
let mut ioslices: Vec<IoSliceMut> = guest_slices
.iter_mut()
.map(|s| IoSliceMut::new(&mut *s))
.collect();
let bytes_read = f.read_vectored(&mut ioslices).await?;
Ok(types::Size::try_from(bytes_read)?)
}
More examples
src/snapshots/preview_1.rs (line 314)
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
async fn fd_read<'a>(
&mut self,
fd: types::Fd,
iovs: &types::IovecArray<'a>,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::READ)?;
let mut guest_slices: Vec<wiggle::GuestSliceMut<u8>> =
iovs.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Iovec = iov_ptr.read()?;
Ok(iov.buf.as_array(iov.buf_len).as_slice_mut()?.expect(
"cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)",
))
})
.collect::<Result<_, Error>>()?;
let mut ioslices: Vec<IoSliceMut> = guest_slices
.iter_mut()
.map(|s| IoSliceMut::new(&mut *s))
.collect();
let bytes_read = f.read_vectored(&mut ioslices).await?;
Ok(types::Size::try_from(bytes_read)?)
}
sourcefn read_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 mut [IoSliceMut<'a>],
_offset: u64
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 mut [IoSliceMut<'a>],
_offset: u64
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Examples found in repository?
src/snapshots/preview_0.rs (line 582)
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
async fn fd_pread<'a>(
&mut self,
fd: types::Fd,
iovs: &types::IovecArray<'a>,
offset: types::Filesize,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::READ | FileCaps::SEEK)?;
let mut guest_slices: Vec<wiggle::GuestSliceMut<u8>> =
iovs.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Iovec = iov_ptr.read()?;
Ok(iov.buf.as_array(iov.buf_len).as_slice_mut()?.expect(
"cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)",
))
})
.collect::<Result<_, Error>>()?;
let mut ioslices: Vec<IoSliceMut> = guest_slices
.iter_mut()
.map(|s| IoSliceMut::new(&mut *s))
.collect();
let bytes_read = f.read_vectored_at(&mut ioslices, offset).await?;
Ok(types::Size::try_from(bytes_read)?)
}
More examples
src/snapshots/preview_1.rs (line 345)
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
async fn fd_pread<'a>(
&mut self,
fd: types::Fd,
iovs: &types::IovecArray<'a>,
offset: types::Filesize,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::READ | FileCaps::SEEK)?;
let mut guest_slices: Vec<wiggle::GuestSliceMut<u8>> =
iovs.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Iovec = iov_ptr.read()?;
Ok(iov.buf.as_array(iov.buf_len).as_slice_mut()?.expect(
"cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)",
))
})
.collect::<Result<_, Error>>()?;
let mut ioslices: Vec<IoSliceMut> = guest_slices
.iter_mut()
.map(|s| IoSliceMut::new(&mut *s))
.collect();
let bytes_read = f.read_vectored_at(&mut ioslices, offset).await?;
Ok(types::Size::try_from(bytes_read)?)
}
sourcefn write_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 [IoSlice<'a>]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn write_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 [IoSlice<'a>]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Examples found in repository?
src/snapshots/preview_0.rs (line 613)
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
async fn fd_write<'a>(
&mut self,
fd: types::Fd,
ciovs: &types::CiovecArray<'a>,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::WRITE)?;
let guest_slices: Vec<wiggle::GuestSlice<u8>> = ciovs
.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Ciovec = iov_ptr.read()?;
Ok(iov
.buf
.as_array(iov.buf_len)
.as_slice()?
.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)"))
})
.collect::<Result<_, Error>>()?;
let ioslices: Vec<IoSlice> = guest_slices
.iter()
.map(|s| IoSlice::new(s.deref()))
.collect();
let bytes_written = f.write_vectored(&ioslices).await?;
Ok(types::Size::try_from(bytes_written)?)
}
More examples
src/snapshots/preview_1.rs (line 376)
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
async fn fd_write<'a>(
&mut self,
fd: types::Fd,
ciovs: &types::CiovecArray<'a>,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::WRITE)?;
let guest_slices: Vec<wiggle::GuestSlice<u8>> = ciovs
.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Ciovec = iov_ptr.read()?;
Ok(iov
.buf
.as_array(iov.buf_len)
.as_slice()?
.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)"))
})
.collect::<Result<_, Error>>()?;
let ioslices: Vec<IoSlice> = guest_slices
.iter()
.map(|s| IoSlice::new(s.deref()))
.collect();
let bytes_written = f.write_vectored(&ioslices).await?;
Ok(types::Size::try_from(bytes_written)?)
}
sourcefn write_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 [IoSlice<'a>],
_offset: u64
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn write_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 mut self,
_bufs: &'life1 [IoSlice<'a>],
_offset: u64
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Examples found in repository?
src/snapshots/preview_0.rs (line 646)
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
async fn fd_pwrite<'a>(
&mut self,
fd: types::Fd,
ciovs: &types::CiovecArray<'a>,
offset: types::Filesize,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::WRITE | FileCaps::SEEK)?;
let guest_slices: Vec<wiggle::GuestSlice<u8>> = ciovs
.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Ciovec = iov_ptr.read()?;
Ok(iov
.buf
.as_array(iov.buf_len)
.as_slice()?
.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)"))
})
.collect::<Result<_, Error>>()?;
let ioslices: Vec<IoSlice> = guest_slices
.iter()
.map(|s| IoSlice::new(s.deref()))
.collect();
let bytes_written = f.write_vectored_at(&ioslices, offset).await?;
Ok(types::Size::try_from(bytes_written)?)
}
More examples
src/snapshots/preview_1.rs (line 409)
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
async fn fd_pwrite<'a>(
&mut self,
fd: types::Fd,
ciovs: &types::CiovecArray<'a>,
offset: types::Filesize,
) -> Result<types::Size, Error> {
let f = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::WRITE | FileCaps::SEEK)?;
let guest_slices: Vec<wiggle::GuestSlice<u8>> = ciovs
.iter()
.map(|iov_ptr| {
let iov_ptr = iov_ptr?;
let iov: types::Ciovec = iov_ptr.read()?;
Ok(iov
.buf
.as_array(iov.buf_len)
.as_slice()?
.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)"))
})
.collect::<Result<_, Error>>()?;
let ioslices: Vec<IoSlice> = guest_slices
.iter()
.map(|s| IoSlice::new(s.deref()))
.collect();
let bytes_written = f.write_vectored_at(&ioslices, offset).await?;
Ok(types::Size::try_from(bytes_written)?)
}
sourcefn seek<'life0, 'async_trait>(
&'life0 mut self,
_pos: SeekFrom
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn seek<'life0, 'async_trait>(
&'life0 mut self,
_pos: SeekFrom
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Examples found in repository?
src/snapshots/preview_1.rs (line 493)
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
async fn fd_seek(
&mut self,
fd: types::Fd,
offset: types::Filedelta,
whence: types::Whence,
) -> Result<types::Filesize, Error> {
use std::io::SeekFrom;
let required_caps = if offset == 0 && whence == types::Whence::Cur {
FileCaps::TELL
} else {
FileCaps::TELL | FileCaps::SEEK
};
let whence = match whence {
types::Whence::Cur => SeekFrom::Current(offset),
types::Whence::End => SeekFrom::End(offset),
types::Whence::Set => SeekFrom::Start(offset as u64),
};
let newoffset = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(required_caps)?
.seek(whence)
.await?;
Ok(newoffset)
}
async fn fd_sync(&mut self, fd: types::Fd) -> Result<(), Error> {
self.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::SYNC)?
.sync()
.await?;
Ok(())
}
async fn fd_tell(&mut self, fd: types::Fd) -> Result<types::Filesize, Error> {
// XXX should this be stream_position?
let offset = self
.table()
.get_file_mut(u32::from(fd))?
.get_cap_mut(FileCaps::TELL)?
.seek(std::io::SeekFrom::Current(0))
.await?;
Ok(offset)
}