As far as I can tell, wit resources can't have fields, only methods.
I'm working on translating some WebIDL files into wit, and I'm trying to figure out the best way to deal with this constraint.
Is the best way to just have setter and getter methods for each field?
There's some discussion here around introducing "properties", but that's more about being able to generate more idiomatic bindings in various languages than doing anything fundamentally new — i.e. it would just be sugar over functions, the same way that resource methods are just functions.
I don't think it would be possible to have directly-accessed fields for resources, because their concrete representation is opaque to code holding a handle to them.
Thanks @Jeff Parsons !
So I guess I'll just make my own getter/setters until this is properly specced.
Here's a list of conversions from WebIDL types to wit types. Some of them are obvious how to convert, but others are not. I wonder what y'all think.
https://github.com/MendyBerger/webidl-wit#conversions-from-webidl-to-wit-types
This looks like a great start! I wouldn't be surprised if over time, Wit adds more types, like BigInt or finite-only floating-point types, and we can refine some of these, but what you have here looks good for now.
I'm thinking that it might make sense to make all function arguments borrow
, since in JS everything is borrowed.
What do y'all think?
Last updated: Nov 22 2024 at 17:03 UTC