autodefault
A library that automatically inserts ..Default::default() for you.
The pitch
Has this ever happened to you?
Wouldn't it be nice if you could omit all the tedious ..Default::default()
calls when building deeply nested struct literals? Now you can! With
autodefault, it's never been easier to build up a large struct literal
for your tests, bevy components, or anything else
you might need!. Simply tag any function with the #[autodefault] attribute
and let us handle the rest:
use autodefault;
// :O
assert_eq!
It's never been easier!
What it's actually doing
When applied to a function, the #[autodefault] will scan the body of the
function for all struct literals that don't already have a ..rest trailing
initializer and insert a ..Default::default(). It will do this unconditionally
for all struct literals, regardless of whether they actually implement
[Default], so be sure to refactor into helper functions as necessary:
use autodefault;
// This will fail to compile