Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created February 25, 2026 01:06
Show Gist options
  • Select an option

  • Save alexcrichton/20e15eb3d9b53db331624c41ec55a585 to your computer and use it in GitHub Desktop.

Select an option

Save alexcrichton/20e15eb3d9b53db331624c41ec55a585 to your computer and use it in GitHub Desktop.
#[allow(unused_variables, dead_code)]
mod my_fs {
use wasi::filesystem::preopens;
use wasi::filesystem::types;
use wasmtime::component::{HasData, Linker, Resource};
wasmtime::component::bindgen!({
with: {
"wasi:clocks": wasmtime_wasi::p2::bindings::clocks,
"wasi:io": wasmtime_wasi::p2::bindings::io,
"wasi:filesystem/types.descriptor": MyDescriptor,
},
require_store_data_send: true,
});
pub struct MyHost<'a> {
_marker: &'a mut u32,
// ..
}
pub struct MyDescriptor {
// ..
}
impl types::Host for MyHost<'_> {
fn filesystem_error_code(
&mut self,
err: Resource<types::Error>,
) -> Option<types::ErrorCode> {
todo!()
}
}
impl types::HostDescriptor for MyHost<'_> {
fn read_via_stream(
&mut self,
self_: Resource<types::Descriptor>,
offset: types::Filesize,
) -> Result<Resource<types::InputStream>, types::ErrorCode> {
todo!()
}
fn write_via_stream(
&mut self,
self_: Resource<types::Descriptor>,
offset: types::Filesize,
) -> Result<Resource<types::OutputStream>, types::ErrorCode> {
todo!()
}
fn append_via_stream(
&mut self,
self_: Resource<types::Descriptor>,
) -> Result<Resource<types::OutputStream>, types::ErrorCode> {
todo!()
}
fn advise(
&mut self,
self_: Resource<types::Descriptor>,
offset: types::Filesize,
length: types::Filesize,
advice: types::Advice,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn sync_data(
&mut self,
self_: Resource<types::Descriptor>,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn get_flags(
&mut self,
self_: Resource<types::Descriptor>,
) -> Result<types::DescriptorFlags, types::ErrorCode> {
todo!()
}
fn get_type(
&mut self,
self_: Resource<types::Descriptor>,
) -> Result<types::DescriptorType, types::ErrorCode> {
todo!()
}
fn set_size(
&mut self,
self_: Resource<types::Descriptor>,
size: types::Filesize,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn set_times(
&mut self,
self_: Resource<types::Descriptor>,
data_access_timestamp: types::NewTimestamp,
data_modification_timestamp: types::NewTimestamp,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn read(
&mut self,
self_: Resource<types::Descriptor>,
length: types::Filesize,
offset: types::Filesize,
) -> Result<(Vec<u8>, bool), types::ErrorCode> {
todo!()
}
fn write(
&mut self,
self_: Resource<types::Descriptor>,
buffer: Vec<u8>,
offset: types::Filesize,
) -> Result<types::Filesize, types::ErrorCode> {
todo!()
}
fn read_directory(
&mut self,
self_: Resource<types::Descriptor>,
) -> Result<Resource<types::DirectoryEntryStream>, types::ErrorCode> {
todo!()
}
fn sync(&mut self, self_: Resource<types::Descriptor>) -> Result<(), types::ErrorCode> {
todo!()
}
fn create_directory_at(
&mut self,
self_: Resource<types::Descriptor>,
path: String,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn stat(
&mut self,
self_: Resource<types::Descriptor>,
) -> Result<types::DescriptorStat, types::ErrorCode> {
todo!()
}
fn stat_at(
&mut self,
self_: Resource<types::Descriptor>,
path_flags: types::PathFlags,
path: String,
) -> Result<types::DescriptorStat, types::ErrorCode> {
todo!()
}
fn set_times_at(
&mut self,
self_: Resource<types::Descriptor>,
path_flags: types::PathFlags,
path: String,
data_access_timestamp: types::NewTimestamp,
data_modification_timestamp: types::NewTimestamp,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn link_at(
&mut self,
self_: Resource<types::Descriptor>,
old_path_flags: types::PathFlags,
old_path: String,
new_descriptor: Resource<types::Descriptor>,
new_path: String,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn open_at(
&mut self,
self_: Resource<types::Descriptor>,
path_flags: types::PathFlags,
path: String,
open_flags: types::OpenFlags,
flags: types::DescriptorFlags,
) -> Result<Resource<types::Descriptor>, types::ErrorCode> {
todo!()
}
fn readlink_at(
&mut self,
self_: Resource<types::Descriptor>,
path: String,
) -> Result<String, types::ErrorCode> {
todo!()
}
fn remove_directory_at(
&mut self,
self_: Resource<types::Descriptor>,
path: String,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn rename_at(
&mut self,
self_: Resource<types::Descriptor>,
old_path: String,
new_descriptor: Resource<types::Descriptor>,
new_path: String,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn symlink_at(
&mut self,
self_: Resource<types::Descriptor>,
old_path: String,
new_path: String,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn unlink_file_at(
&mut self,
self_: Resource<types::Descriptor>,
path: String,
) -> Result<(), types::ErrorCode> {
todo!()
}
fn is_same_object(
&mut self,
self_: Resource<types::Descriptor>,
other: Resource<types::Descriptor>,
) -> bool {
todo!()
}
fn metadata_hash(
&mut self,
self_: Resource<types::Descriptor>,
) -> Result<types::MetadataHashValue, types::ErrorCode> {
todo!()
}
fn metadata_hash_at(
&mut self,
self_: Resource<types::Descriptor>,
path_flags: types::PathFlags,
path: String,
) -> Result<types::MetadataHashValue, types::ErrorCode> {
todo!()
}
fn drop(&mut self, rep: Resource<types::Descriptor>) -> wasmtime::Result<()> {
todo!()
}
}
impl types::HostDirectoryEntryStream for MyHost<'_> {
fn read_directory_entry(
&mut self,
self_: Resource<types::DirectoryEntryStream>,
) -> Result<Option<types::DirectoryEntry>, types::ErrorCode> {
todo!()
}
fn drop(&mut self, rep: Resource<types::DirectoryEntryStream>) -> wasmtime::Result<()> {
todo!()
}
}
impl preopens::Host for MyHost<'_> {
fn get_directories(&mut self) -> Vec<(Resource<types::Descriptor>, String)> {
todo!()
}
}
pub fn add_to_linker<T>(
linker: &mut Linker<T>,
get: fn(&mut T) -> MyHost<'_>,
) -> wasmtime::Result<()> {
struct MyData;
impl HasData for MyData {
type Data<'a> = MyHost<'a>;
}
types::add_to_linker::<_, MyData>(linker, get)?;
preopens::add_to_linker::<_, MyData>(linker, get)?;
Ok(())
}
}
fn main() {
// ..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment