dzamlo / rust-bitfield

This crate provides macros to generate bitfield-like struct.
Apache License 2.0
157 stars 19 forks source link

Generate Constructors #45

Closed PokeJofeJr4th closed 4 months ago

PokeJofeJr4th commented 4 months ago

As of this writing, using impl new; creates a constructor with parameters and calls for all setters. Using impl new {func_name(setter: ty, ...); creates a constructor called func_name with the specified arguments that calls setters with the given type.

Ideally I'd want to use the names of the getters as function parameters, since those are generally a better representation of what the field is, and I'd like to grab the types from the field definition as well. However, unless there's a good way to check if two identifiers are the same, this seems impossible to do without procedural macros

Originally #18

dzamlo commented 4 months ago

While it would be nice to be able to use the names of the getters, I don't think this is a big issue. I think we can go ahead with this version.

dzamlo commented 4 months ago

I think this should be documented in the bitfield docs too.

PokeJofeJr4th commented 4 months ago

Alright, everything you mentioned here should be addressed at this point. Let me know if there's anything else I can work on!

dzamlo commented 4 months ago

Nice! Thanks very much for your work. Will release this ASAP.