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
531 stars 51 forks source link

Support overloading #234

Open Manishearth opened 2 years ago

Manishearth commented 2 years ago

Related: https://github.com/rust-diplomat/diplomat/issues/166

This would have to be backend-specific, but it would be nice to be able to overload across FFI where possible.

Instead of a #[diplomat::overload] attribute, the design I'm thinking would be #[diplomat::rename(cpp, "foo_bar")] (renaming is useful anyway), and in case of clashes, the backend figures out if stuff is overloadable and handles it if so.

For example, in C++ stuff is overloadable as long as the signatures are different. In JS, you can overload different structs provided they have different fields (this is similar to typescript | sum types), or if the types are different enough. The C backend is raw FFI so I'd prefer to not have overloading at all.

I can imagine constructors (#166) being handled with rename(constructor) or something

Manishearth commented 2 years ago

If we do this we should do this in the holistic backend attribute system designed in #235