Node icon indicating copy to clipboard operation
Node copied to clipboard

Utility covering up as_ref().expect() etc.

Open bertllll opened this issue 3 years ago • 0 comments

We agreed that probably a macro or some other form of utility could be written to allow us write less code which repeat frequently - this time the concern goes after all alternatives of:

.as_ref().expect().something
.as_mut().expect().something
.as_ref().expect().something().expect()

or even

.as_ref().expect().something.as_ref().expect()

and maybe some least frequent variants.

Notice that it is always about data structures that can be unwrapped.

The interface of the utility must be as small as possible so that it won't disturb us even more at our work once implemented. The goal would also be to write as few instances of different utilities as possible, hopefully with just one needed.

One suggestion is to use simple generic functions. But if we want to meet the second requirement, I think, the only way to go is with a procedural macro which would examine the supplied structure at the compilation time and find a resolution of the problem and return necessary code doing exactly that.

bertllll avatar May 20 '22 13:05 bertllll