In my code I have a lot of structs with Option<T>
s in them. I need to work with them in a lot of places, so my code is littered with struct accesses like car.engine.as_ref().unwrap()
. This is pain for code readability.
Is there a default function on the Option<T>
type that does the same? Like car.engine.get()
? Of course I could write accessor functions for every struct member, but this seems like an overkill for something so basic. Am I doing it wrong?
I don't know much about macros, but is there a way to shorten it with macros?