Stream: general

Topic: ✔ WIT: Failable constructor?


view this post on Zulip Lann Martin (May 08 2025 at 13:27):

Constructors can only return the type they are associated with, which matches typical native constructors (e.g. new Thing() in javascript). You can instead use a "static function":

resource mystruct {
    make-fallibly: static func(a: u32) -> result<mystruct, my-error>;
}

In rust you would call this like Mystruct::make_fallibly(a).

view this post on Zulip Bogdan Arabadzhi (May 08 2025 at 13:35):

Yep, that's what I ended up with.
Thanks @Lann Martin :+1:

view this post on Zulip Notification Bot (May 08 2025 at 13:35):

Bogdan Arabadzhi has marked this topic as resolved.


Last updated: Dec 06 2025 at 05:03 UTC