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

Refactor Field type to have class path and field name as const parameters #2

Open
giovanniberti opened this issue Apr 15, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@giovanniberti
Copy link
Owner

This would change Field definition from

struct Field<'env: 'borrow, 'borrow, T> { /* ... */ }

to

struct Field<'env: 'borrow, 'borrow, const CLASSPATH_PATH: &str, const FIELD_NAME: &str, T> { /* ... */ }

This change would allow:

  1. More type safety around fields (you could not directly assign a class field where another class field is expected), even though I don't know how much useful this kind of safety would be
  2. Removal of the #[field] attribute in *FromJavaValue derive macros for Field fields

Moreover, in *FromJavaValue derive macros we could still ensure that the two constant parameters match the declared package and class name.

With some macro trickery we could perhaps include a "pseudo type macro" Field! that expands to the correct Field<...> type and does not actually exist but is instead manually expanded by the derive macros.

Blocked by rust-lang/rust#44580

@giovanniberti giovanniberti added the enhancement New feature or request label Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant