Re:When to use generics
by 0x6877 on Wednesday April 13, 2022 @03:57AM
(#31012195)
Sometimes you need to instantiate a struct, usually in a test, that contains a bunch of pointers to built in types. Say a struct representing a json request body with optional fields. You can’t just take a pointer to a string literal `&”foo”` and making a variable for everyone of these fields is cumbersome so you have a function that returns a pointer to the value it’s given.
I’ve personally never needed it outside of tests.