At the moment I can't use wit-bindgen to generate types and traits for a library and then provide a more ergonomic wrapper for Rust at least.
The goal is to provide a library api like this:
pub trait Library {
fn new() -> Result<Self>;
}
// This type is effectively thunks which may manage some internal state and call into the trait implementation of T.
struct LibraryImpl<T> { ... }
impl<T: Library> GuestWhatever for LibraryImpl<T> { ... }
And the user would implement the trait and use a macro to generate the component entrypoints, delegating the implementation to LibraryImpl
.
pub struct Implementation {}
impl Library for Implementation { ... }
// This macro effectively would tell wit-bindgen to generate entrypoints targeting LibraryImpl<Implementation>.
library_crate::implement!(Implementation);
At the moment this type of API would be blocked on two things:
Any other thoughts on what might be needed for this?
For use case, I plan to provide a wgpu context implementation that you can ask for that is constructed for you and delegates via the component model to the runtime. (Instead of using the raw wit-bindgen generated types which won't work with the wgpu ecosystem)
Last updated: Nov 22 2024 at 16:03 UTC