It seems like resources defined in wit
files cannot return an error, or any value?
I tried:
constructor(id: string) -> result<_, string>
However it isn't valid syntax since it wants an ;
immediately after the )
.
I'm assuming this was initially intentional, however is there a good reason for having this restriction where constructors cannot fail?
I'm not sure how to model it so that it can fail, unless I did something like:
resource agg {
constructor();
init(id: string) -> result<_, string>;
}
But the rust code would just be Default::default()
for the constructor, and the init would set the ID string?
It's a little messy and it would be much more convenient if I could just return the error directly from the constructor.
not all languages support fallible constructors, and we want to provide the ability to create good bindings for all languages, including those.
What you can do instead is add a static function that can internally call the constructor, but returns a result:
resource agg {
constructor();
from_id: static func(id: string) -> result<agg, string>;
}
Note that if you only want a resource to be produced via the static function you shouldn't define constructor();
at all; it is only for exporting infallible constructors.
ah okay, that solves it entirely I guess! Thanks a lot
Last updated: Nov 22 2024 at 17:03 UTC