deku icon indicating copy to clipboard operation
deku copied to clipboard

Request for Enhancement: Project-level Deku settings

Open v1gnesh opened this issue 3 years ago • 9 comments

Project-level settings that are set within main.rs can help reduce boilerplate significantly. Imagine a #[deku(endian = "little")] for each & every struct or enum. This will make a very noticable difference in readability when working on projects with hundreds of structs and enums.

Over time, project-level settings can be used for future enhancements whenever they come up.

As always, thanks for your time & effort to all the contributors of this very neat project.

v1gnesh avatar May 20 '21 13:05 v1gnesh

Is this possible? I think there is no way to access such file level settings in a procedure macro.

constfold avatar May 31 '21 06:05 constfold

Any further thoughts on this, @sharksforarms? Perhaps a .conf file with global settings?

v1gnesh avatar Jun 18 '21 04:06 v1gnesh

Any further thoughts on this, @sharksforarms? Perhaps a .conf file with global settings?

This would be better suited in another library using deku. For example, another proc-macro crate which annotates struct/enum fields with deku attributes

sharksforarms avatar Jun 19 '21 01:06 sharksforarms

Could you show me an example of such a crate/project please?

v1gnesh avatar Jun 19 '21 02:06 v1gnesh

Could you show me an example of such a crate/project please?

The following is an example of using deku attributes in another proc-macro library. If that is what you are asking.

https://github.com/wcampbell0x2a/bintex

wcampbell0x2a avatar Jun 19 '21 02:06 wcampbell0x2a

@constfold Any thoughts on https://github.com/sharksforarms/deku/issues/225#issuecomment-864578411 ? Does an attribute named ctx_nested make sense?

sharksforarms avatar Jun 22 '21 12:06 sharksforarms

Hi @sharksforarms & @wcampbell0x2a, check these out. nom's declarative parser seems to be catching up.

nom-derive-impl/src/config.rs Overriding the default endianness

This will cut my boilerplate noticeably.

v1gnesh avatar Aug 23 '21 15:08 v1gnesh

I'm still not sure how I'd like to approach this, if at all. Have you considered writing your own proc-macro to accomplish this?

I'll try and give you an example when I have time to create one.

sharksforarms avatar Aug 23 '21 21:08 sharksforarms

Thank you. As I had mentioned, I'm a noob at programming, barely capable of using this library. It'll take me a long long time to get comfortable enough to work on proc-macros.

The approach taken by nom-derive seems straightforward (to a user), no?

v1gnesh avatar Aug 24 '21 04:08 v1gnesh