rust-diplomat / diplomat

Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code
https://rust-diplomat.github.io/book/
Other
532 stars 51 forks source link

JS2 constructors: structs and enums should autoconvert at parameter/struct boundaries #720

Open Manishearth opened 3 weeks ago

Manishearth commented 3 weeks ago

Currently in JS2 it's possible to do new Struct(..fields) (this will change slightly in https://github.com/rust-diplomat/diplomat/issues/719), and new Enum("variantName"). We should also support using {...} in place of structs and "variantName" in place of enums in parameters and struct fields, so the following should just work:

let result = Foo.takesNestedStruct({ a: 1, innerStruct: { b: 3, c: 4 }, enumValue: "foo"  })

Probably this can be done with a .fromSuppliedValue() method (or a [diplomatRuntime.fromSuppliedValue] Symbol?) on every enum/struct that gets unconditionally called when attempting to treat a value as that type in params or struct field construction.