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: Dec 23 2024 at 12:05 UTC