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 getter/setter for fields #16

Closed
fafhrd91 opened this issue May 30, 2017 · 13 comments
Closed

Generate getter/setter for fields #16

fafhrd91 opened this issue May 30, 2017 · 13 comments
Labels

Comments

@fafhrd91
Copy link
Contributor

Add proc attr that automatically creates getter and setter for struct field

#[py::class]
struct cls {
    #[prop(setter, getter)]
    num: i32
}
@fafhrd91 fafhrd91 added the easy label Jun 8, 2017
@fafhrd91
Copy link
Contributor Author

@messense want to do this too?

@messense
Copy link
Member

I am not sure about this one. I don't know much about syn, might need to take some time learning the basics. Debugging isn't easy either.

@fafhrd91
Copy link
Contributor Author

You can always use println! Also cargo expand shows expanded macros.

@messense
Copy link
Member

I'll give it a try.

@messense
Copy link
Member

messense commented Aug 2, 2017

messense@b10089d

Progress so far. Not sure how to add impls, it's not like #[methods] that already have impl blocks.

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Aug 2, 2017

you can access attributes of struct, so just generate wrap method and directly access attributes.
also you can create multiple impl blocks

@messense
Copy link
Member

messense commented Aug 4, 2017

I need syn::Ty of the struct but I only have syn::Ident, not sure how to get syn::Ty for the struct from syn::DeriveInput

https://dtolnay.github.io/syn/syn/struct.DeriveInput.html

@messense
Copy link
Member

messense commented Aug 4, 2017

I don't think so, that gives me syn::Ty of the struct field while I need syn::Ty of the struct itself to pass to impl_wrap_getter/impl_wrap_setter

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Aug 4, 2017

but all you need is name of the struct, it is type.

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Aug 4, 2017

@messense
Copy link
Member

messense commented Aug 4, 2017

I tried but there are a lot of subtle details that I am not aware of. I doubt I can finish this recently so if you want to implement it yourself it's ok.

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Aug 4, 2017

It is fine, it is not priority

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

No branches or pull requests

2 participants