-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Having exploited the instant crate in my toy WebAssembly game that I've been playing around with, I have come to the conclusion that the way that Cargo features are defined for this crate is a little sub-optimal for two reasons:
-
They're not self documenting. That is to say, if one intends to target
wasm32usingwasm-bindgenand expects thatinstantwill, therefore, use the JavaScriptperformance.now(), one MUST express thewasm-bindgenfeature flag forinstant(similarly, forstdweb) but the requirement to do so is easy to miss and missing it results in a rather obtuse error related to JavaScript module imports, at runtime. -
Cargo feature flags are supposed to be strictly additive. The Cargo Book says: "...enabling a feature should not disable functionality..." The existence of the
inaccuratefeature directly contravenes this recommendation and is, for me, an issue because my use-case requires accurate, high-precision performance counters and thus requires me to be sure thatinaccuratewill not be set.- Tangent: I didn't go to all that trouble setting COOP / COEP headers just for another Cargo dep. to sink my timer precision!
I'm happy to help fix this and submit a merge request, improving the use of feature flags, but I am not entirely sure how this should or even could be done, without introducing breaking changes to the crate. My first thought was to handle the first problem with a compilation warning that could be dismissed by setting a feature -- perhaps named js-extern-now -- indicating that the user did, indeed, expect instant to find now() as a JS extern. To handle case 2, perhaps introducing a precise feature which overrides (or conflicts) with inaccurate would help but that seems somewhat messy.