I am creating a custom wit world for my components. These components take a file as input and do some calculations, returning the result. My current design was using descriptor as the module's function argument:
world myworld {
interface calc {
use wasi:filesystem@0.2.5.preopen.{descriptor};
calculate: func(file: descriptor) -> s64;
}
}
However, I noticed that the descriptor resource does not implement std::io::{Read, Seek}, which I require.
Is there any way to make this work besides relying on std::fs::File and reading the file inside the component ? That would require me to provide the input at a static location, for example /input.bin.
Thank you!
wit-bindgen just knows how to create rust bindings to wit interfaces and types, it doesnt know how to map anything to the types in std.
wit-bindgen will create a struct Descriptor and that should have methods on it such as read_via_stream and write_via_stream
heres what wit-bindgen produces on just the wasi wits, in the wasi crate: https://docs.rs/wasi/latest/wasi/filesystem/types/struct.Descriptor.html
if you need std::io::Read you can impl that on https://docs.rs/wasi/latest/wasi/filesystem/types/type.InputStream.html using blocking_read.
if you need Seek, you'll have to make your own struct that contains a Descriptor and the offset, track changes to the offset as you seek or read, and open a new stream when you need to read at a new offset.
one day it may be easier to do all of that with std, but right now std isnt using Descriptors under the hood, so unfortunately you have to wire some of this up yourself.
this is a very sketchy overview, happy to dive more into the details of any of these points as you need.
Last updated: Dec 06 2025 at 07:03 UTC