Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate method groups in rust? #96

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kaesaecracker
Copy link

Motivation

I am working on a rust library that can be used from multiple languages. To reduce development complexity, I try to generate as much code of the language bindings as possible. For the C# bindings, I use the C binding as a basis.

The existing code generator in C# does not fit my use case, as the resulting API is fine for internal use, put lacks the polish I want for a safe-ish public API. The approach I tried here means I only have to create a new C API and a C# method "magically" shows up in the git diff.

State of the patch set

The code is not final by any means - it contains TODOs and currently breaks when not following a specific naming convention for example.
I also changed to much unrelated code and did not structure the commits properly.

For my specific use case, it seems to work fine. The code in cccb/servicepoint#16 crates/servicepoint_binding_cs/ServicePoint/*.g.cs is generated by my fork.

I am open to basically starting from scratch again or splitting the changes into multiple patch sets for upstreaming.

My questions for you

  1. Is there a chance any of this functionality can be upstreamed in some form? Would something like this even be useful to others?
  2. If I cannot upstream, would you accept PRs that apply refactorings that make something like my fork easier to maintain?
  3. The code currently reacts to a magic string in the docs, what would be a better approach for differentiating methods that expect to own the passed instance? If possible, this would also allow the generator to generate properties instead of methods in some cases.
  4. Would I be allowed to try to create a thin C# code generation abstraction?
  5. I added a new dependency in my fork - is that okay? If so, I would try to see if there is other code that can be replaced by using this library.
  6. My current approach for returning "memory" from rust code is returning a struct with a pointer and a length. Is there something that can be used that would allow the code generator so special case this as a Span<byte>?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant