pub struct WasiFilesystemNamed<T>(/* private fields */);Expand description
A helper struct which implements HasData for the wasi:filesystem APIs
when used in combination with named imports.
This structure is similar in purpose to WasiFilesystem and is used
when using the named_imports module for wasi:filesystem. This structure
serves as the D type parameter for add_to_linker functions.
§Meaning of the T parameter
Here the T must be something that implements WasiFilesystemNamedView. The
corresponding Data for this type is WasiCtxNamedView which internally
will contain &mut T.
Effectively you’re going to implement WasiFilesystemNamedView for something in
your embedding, and that’s the T you’ll fill in here.
§Examples
use wasmtime::component::{Linker, Component, ResourceTable};
use wasmtime::{Engine, Result};
use wasmtime_wasi::{NamedId, WasiCtxNamedView};
use wasmtime_wasi::filesystem::*;
use wasmtime_wasi::p2::bindings::named_imports;
use std::collections::HashMap;
struct MyStoreState {
table: ResourceTable,
states: HashMap<NamedId, WasiFilesystemCtx>,
}
fn main() -> Result<()> {
let engine = Engine::default();
let mut linker = Linker::new(&engine);
let component = Component::new(&engine, "(component)")?;
let mut name_map = HashMap::new();
named_imports::wasi::filesystem::preopens::add_to_linker::<MyStoreState, WasiFilesystemNamed<MyStoreState>>(
&mut linker,
&component,
|name| {
let len = name_map.len();
Ok(NamedId(*name_map.entry(name.to_string()).or_insert(len)))
},
|state| WasiCtxNamedView(state),
)?;
Ok(())
}
impl WasiFilesystemNamedView for MyStoreState {
fn filesystem(&mut self, id: NamedId) -> WasiFilesystemCtxView<'_> {
let ctx = self.states.get_mut(&id).expect("state for id");
WasiFilesystemCtxView {
table: &mut self.table,
ctx,
}
}
}Trait Implementations§
Source§impl<T> HasData for WasiFilesystemNamed<T>where
T: WasiFilesystemNamedView,
impl<T> HasData for WasiFilesystemNamed<T>where
T: WasiFilesystemNamedView,
Source§type Data<'a> = WasiCtxNamedView<'a, T>
type Data<'a> = WasiCtxNamedView<'a, T>
The data associated with this trait implementation, chiefly used as a
generic associated type to allow plumbing the
'a lifetime into the
definition here. Read moreSource§impl<T, U> HostDescriptorWithStore<U> for WasiFilesystemNamed<T>where
T: WasiFilesystemNamedView,
Available on crate feature p3 only.
impl<T, U> HostDescriptorWithStore<U> for WasiFilesystemNamed<T>where
T: WasiFilesystemNamedView,
Available on crate feature
p3 only.Source§fn read_via_stream(
store: Access<'_, U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
offset: Filesize,
) -> Result<(StreamReader<u8>, FutureReader<Result<(), ErrorCode>>)>
fn read_via_stream( store: Access<'_, U, Self>, id: NamedId, fd: Resource<Descriptor>, offset: Filesize, ) -> Result<(StreamReader<u8>, FutureReader<Result<(), ErrorCode>>)>
Return a stream for reading from a file. Read more
Source§fn write_via_stream(
store: Access<'_, U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
data: StreamReader<u8>,
offset: Filesize,
) -> Result<FutureReader<Result<(), ErrorCode>>>
fn write_via_stream( store: Access<'_, U, Self>, id: NamedId, fd: Resource<Descriptor>, data: StreamReader<u8>, offset: Filesize, ) -> Result<FutureReader<Result<(), ErrorCode>>>
Return a stream for writing to a file, if available. Read more
Source§fn append_via_stream(
store: Access<'_, U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
data: StreamReader<u8>,
) -> Result<FutureReader<Result<(), ErrorCode>>>
fn append_via_stream( store: Access<'_, U, Self>, id: NamedId, fd: Resource<Descriptor>, data: StreamReader<u8>, ) -> Result<FutureReader<Result<(), ErrorCode>>>
Return a stream for appending to a file, if available. Read more
Source§async fn advise(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
offset: Filesize,
length: Filesize,
advice: Advice,
) -> FilesystemResult<()>
async fn advise( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, offset: Filesize, length: Filesize, advice: Advice, ) -> FilesystemResult<()>
Provide file advisory information on a descriptor. Read more
Source§async fn sync_data(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
) -> FilesystemResult<()>
async fn sync_data( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, ) -> FilesystemResult<()>
Synchronize the data of a file to disk. Read more
Source§async fn get_flags(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
) -> FilesystemResult<DescriptorFlags>
async fn get_flags( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, ) -> FilesystemResult<DescriptorFlags>
Get flags associated with a descriptor. Read more
Source§async fn get_type(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
) -> FilesystemResult<DescriptorType>
async fn get_type( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, ) -> FilesystemResult<DescriptorType>
Get the dynamic type of a descriptor. Read more
Source§async fn set_size(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
size: Filesize,
) -> FilesystemResult<()>
async fn set_size( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, size: Filesize, ) -> FilesystemResult<()>
Adjust the size of an open file. If this increases the file’s size, the
extra bytes are filled with zeros. Read more
Source§async fn set_times(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
data_access_timestamp: NewTimestamp,
data_modification_timestamp: NewTimestamp,
) -> FilesystemResult<()>
async fn set_times( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, data_access_timestamp: NewTimestamp, data_modification_timestamp: NewTimestamp, ) -> FilesystemResult<()>
Adjust the timestamps of an open file or directory. Read more
Source§fn read_directory(
store: Access<'_, U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
) -> Result<(StreamReader<DirectoryEntry>, FutureReader<Result<(), ErrorCode>>)>
fn read_directory( store: Access<'_, U, Self>, id: NamedId, fd: Resource<Descriptor>, ) -> Result<(StreamReader<DirectoryEntry>, FutureReader<Result<(), ErrorCode>>)>
Read directory entries from a directory. Read more
Source§async fn sync(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
) -> FilesystemResult<()>
async fn sync( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, ) -> FilesystemResult<()>
Synchronize the data and metadata of a file to disk. Read more
Source§async fn create_directory_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path: String,
) -> FilesystemResult<()>
async fn create_directory_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path: String, ) -> FilesystemResult<()>
Create a directory. Read more
Source§async fn stat(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
) -> FilesystemResult<DescriptorStat>
async fn stat( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, ) -> FilesystemResult<DescriptorStat>
Return the attributes of an open file or directory. Read more
Source§async fn stat_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path_flags: PathFlags,
path: String,
) -> FilesystemResult<DescriptorStat>
async fn stat_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path_flags: PathFlags, path: String, ) -> FilesystemResult<DescriptorStat>
Return the attributes of a file or directory. Read more
Source§async fn set_times_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path_flags: PathFlags,
path: String,
data_access_timestamp: NewTimestamp,
data_modification_timestamp: NewTimestamp,
) -> FilesystemResult<()>
async fn set_times_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path_flags: PathFlags, path: String, data_access_timestamp: NewTimestamp, data_modification_timestamp: NewTimestamp, ) -> FilesystemResult<()>
Adjust the timestamps of a file or directory. Read more
Source§async fn link_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
old_path_flags: PathFlags,
old_path: String,
new_fd: Resource<Descriptor>,
new_path: String,
) -> FilesystemResult<()>
async fn link_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, old_path_flags: PathFlags, old_path: String, new_fd: Resource<Descriptor>, new_path: String, ) -> FilesystemResult<()>
Create a hard link. Read more
Source§async fn open_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path_flags: PathFlags,
path: String,
open_flags: OpenFlags,
flags: DescriptorFlags,
) -> FilesystemResult<Resource<Descriptor>>
async fn open_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path_flags: PathFlags, path: String, open_flags: OpenFlags, flags: DescriptorFlags, ) -> FilesystemResult<Resource<Descriptor>>
Open a file or directory. Read more
Source§async fn readlink_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path: String,
) -> FilesystemResult<String>
async fn readlink_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path: String, ) -> FilesystemResult<String>
Read the contents of a symbolic link. Read more
Source§async fn remove_directory_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path: String,
) -> FilesystemResult<()>
async fn remove_directory_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path: String, ) -> FilesystemResult<()>
Remove a directory. Read more
Source§async fn rename_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
old_path: String,
new_fd: Resource<Descriptor>,
new_path: String,
) -> FilesystemResult<()>
async fn rename_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, old_path: String, new_fd: Resource<Descriptor>, new_path: String, ) -> FilesystemResult<()>
Rename a filesystem object. Read more
Source§async fn symlink_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
old_path: String,
new_path: String,
) -> FilesystemResult<()>
async fn symlink_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, old_path: String, new_path: String, ) -> FilesystemResult<()>
Create a symbolic link (also known as a “symlink”). Read more
Source§async fn unlink_file_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path: String,
) -> FilesystemResult<()>
async fn unlink_file_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path: String, ) -> FilesystemResult<()>
Unlink a filesystem object that is not a directory. Read more
Source§async fn is_same_object(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
other: Resource<Descriptor>,
) -> Result<bool>
async fn is_same_object( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, other: Resource<Descriptor>, ) -> Result<bool>
Test whether two descriptors refer to the same filesystem object. Read more
Source§async fn metadata_hash(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
) -> FilesystemResult<MetadataHashValue>
async fn metadata_hash( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, ) -> FilesystemResult<MetadataHashValue>
Return a hash of the metadata associated with a filesystem object referred
to by a descriptor. Read more
Source§async fn metadata_hash_at(
store: &Accessor<U, Self>,
id: NamedId,
fd: Resource<Descriptor>,
path_flags: PathFlags,
path: String,
) -> FilesystemResult<MetadataHashValue>
async fn metadata_hash_at( store: &Accessor<U, Self>, id: NamedId, fd: Resource<Descriptor>, path_flags: PathFlags, path: String, ) -> FilesystemResult<MetadataHashValue>
Return a hash of the metadata associated with a filesystem object referred
to by a directory descriptor and a relative path. Read more
Auto Trait Implementations§
impl<T> Freeze for WasiFilesystemNamed<T>
impl<T> RefUnwindSafe for WasiFilesystemNamed<T>
impl<T> Send for WasiFilesystemNamed<T>
impl<T> Sync for WasiFilesystemNamed<T>
impl<T> Unpin for WasiFilesystemNamed<T>
impl<T> UnsafeUnpin for WasiFilesystemNamed<T>
impl<T> UnwindSafe for WasiFilesystemNamed<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<H, T> HostDescriptorWithStore<T> for H
impl<H, T> HostDescriptorWithStore<T> for H
impl<H, T> HostDescriptorWithStore<T> for H
impl<H, T> HostDirectoryEntryStreamWithStore<T> for H
impl<H, T> HostDirectoryEntryStreamWithStore<T> for H
impl<H, T> HostDirectoryEntryStreamWithStore<T> for H
impl<H, T> HostErrorWithStore<T> for H
impl<H, T> HostIncomingDatagramStreamWithStore<T> for H
impl<H, T> HostIncomingDatagramStreamWithStore<T> for H
impl<H, T> HostIncomingDatagramStreamWithStore<T> for H
impl<H, T> HostInputStreamWithStore<T> for H
impl<H, T> HostInputStreamWithStore<T> for H
impl<H, T> HostNetworkWithStore<T> for H
impl<H, T> HostNetworkWithStore<T> for H
impl<H, T> HostOutgoingDatagramStreamWithStore<T> for H
impl<H, T> HostOutgoingDatagramStreamWithStore<T> for H
impl<H, T> HostOutgoingDatagramStreamWithStore<T> for H
impl<H, T> HostOutputStreamWithStore<T> for H
impl<H, T> HostOutputStreamWithStore<T> for H
impl<H, T> HostPollableWithStore<T> for H
impl<H, T> HostPollableWithStore<T> for H
impl<H, T> HostResolveAddressStreamWithStore<T> for H
impl<H, T> HostResolveAddressStreamWithStore<T> for H
impl<H, T> HostResolveAddressStreamWithStore<T> for H
impl<H, T> HostTcpSocketWithStore<T> for H
impl<H, T> HostTcpSocketWithStore<T> for H
impl<H, T> HostTcpSocketWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostUdpSocketWithStore<T> for H
impl<H, T> HostUdpSocketWithStore<T> for H
impl<H, T> HostUdpSocketWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostUdpSocketWithStore<T> + HostIncomingDatagramStreamWithStore<T> + HostOutgoingDatagramStreamWithStore<T> + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostDescriptorWithStore<T> + HostDirectoryEntryStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostUdpSocketWithStore<T> + HostIncomingDatagramStreamWithStore<T> + HostOutgoingDatagramStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostDescriptorWithStore<T> + HostDirectoryEntryStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostUdpSocketWithStore<T> + HostIncomingDatagramStreamWithStore<T> + HostOutgoingDatagramStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more