Any Crates for Deriving an "All Fields Optional" Version of Struct for Patching the Original?

I have a situation where I want to take a struct, and be able to derive() an equivalent struct that has all of the fields as Option's that I can then use to update the original struct for every field that is Some(value).

Does anybody know if there are any existing crates that do this? I haven't found any in my searches, but it's a little hard to guess/find what it might be named so I might have missed it.

Maybe write macros, and that would suffice?

Yeah, I figure I coudl figure out how to write the macros, I just wanted to make sure that they didn't already exist.

derive_builder is targeted at a different use case, but it does generate a version of the struct where all fields are wrapped in Option. It might be usable for this, or at least have some useful code to copy.

2 Likes