top | item 45049967

(no title)

bkolobara | 6 months ago

Your Rust example would not work, because `window.set_href("/foo")` would not return anything (it would return the unit type "()" aka void). And you can't call `set_href()` again on "()". This is a common pattern in Rust, allow certain functions to only be called once on specific objects.

I really like your TypeScript solution! This actually perfectly solves the issue. I just wish that this was the ONLY way to actually do it, so I would not have experience the issue in the first place.

discuss

order

johnfn|6 months ago

Thanks for the explanation! That's a very nice pattern.

> I just wish that this was the ONLY way to actually do it

I completely agree.