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

Add a derive macro for CustomType #817

Merged
merged 2 commits into from
Jan 25, 2024
Merged

Add a derive macro for CustomType #817

merged 2 commits into from
Jan 25, 2024

Conversation

MavethGH
Copy link
Contributor

The macro currently generates getters and setters for all fields in the struct, and has helper attributes for overriding generated getter/setter functions. There is also a readonly helper attribute that prevents a setter from being registered.

TODOs:

  • Docs docs docs
  • More tests
  • Register a pretty-print name for types
  • Attribute for calling a user-provided function with the TypeBuilder passed in
    • What would it be called?
    • Do we call it before or after registering everything else?
  • Attribute for skipping a field entirely
  • Support for tuple structs
    • What would the fields be named? field0, field1, etc perhaps?
  • Support for enums as described in the book

@schungx
Copy link
Collaborator

schungx commented Jan 21, 2024

Looking good!

Let me know when to merge.

@schungx schungx merged commit 9a82471 into rhaiscript:main Jan 25, 2024
39 checks passed
@schungx
Copy link
Collaborator

schungx commented Jan 25, 2024

So below is list of all the attributes so far...

  • All fields (pub or private) will be exported
    • perhaps later a skip attribute
  • #[readonly] => only getter, no setter
  • #[get] => generated getter
    • #[get(func_name)] => use func_name as getter function
  • #[set] => generated setter
    • #[set(func_name)] => use func_name as setter function
  • omitted => generated getter and setter

Did I miss anything?

@schungx
Copy link
Collaborator

schungx commented Jan 25, 2024

Unfortunately we cannot make #[get(func_name)] use a standard getter signature with &self instead of &mut self which is quite unusual for normal structs...

@schungx
Copy link
Collaborator

schungx commented Jan 25, 2024

I'll open another tracking issue...

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.

None yet

2 participants