COMMUNITY

Some questions coming from Rust (enums/traits)

  • Can you customize the deserialization of an enum?

  • Can you implement methods for enums?

  • Can you implement methods for foreign types? (e.g. can I add an inline method to js.html.CanvasElement objects?)

(Note that static extension is purely compile time syntax sugar, it simply transforms x.staticExtension() into pack.Class.staticExtension(x))

1 Like

Thanks for the quick answer :slight_smile:

My Haxe application is consuming a JSON API … I would like to serialize / deserialize some part of it from/into a Haxe enum.

Thanks, static extensions are exactly what I was looking for!

  1. Yes. Try tink_json or json2object or haxe.Serializer
  2. Yes. Try adding @:using to your enum
  3. Yes. You can add inline functions to extern.
3 Likes