openmina / mina-p2p-messages-rs

1 stars 0 forks source link

Add `derive_more::Deref` to generated types #37

Closed sebastiencs closed 1 year ago

sebastiencs commented 1 year ago

This adds Deref implementation to tuples with a single element. This is to avoid having to use multiples .0 to reach the inner element, that's a bit confusing to read and write.

See this commit for example: https://github.com/name-placeholder/mina-block-verifier-poc/commit/fe5f0f54741ff68d52dcf97ac77303d2496af235

@akoptelov I have manually added derive_more::Deref to the generated types (in src/v2/generated.rs). Next time those types are automatically generated, would it be possible to add Deref too ? I'm not sure where they are generated, could you point me to where I could add Deref automatically ?

akoptelov commented 1 year ago

I've added an item here: name-placeholder/bin-prot-rs/issues/3

sebastiencs commented 1 year ago

LGTM @sebastiencs regarding generated code, let's keep it like this for now, since currently it is only possible to add exactly the samederive to all types, and here we only should add Deref to newtype-like structs. I need to extend the generator for that.

@akoptelov Alright, another solution would be to have our own derive trait, like MaybeDeref, which would implement std::ops::Deref for new types only. We could then add MaybeDeref to all the generated types

I've fixed the compilation