I have a big struct Foo
, and want to map
it into a Foo
where most of the fields don\'t need updating. I was hoping t
Is there syntax for moving fields between similar structs?
No. There is no such syntax. The current implementation of "struct update" (previously called "functional record update") syntax only allows the exact same type.
Is there better syntax for this somewhere, or a better way to implement these map-like methods for non-trivial structs?
No. The only suggestion I have is to destructure your original struct and then recreate it. You also don't need the ::<R>
as it's inferred.
let Foo { a, b, c, d, e, t } = q;
let r = Foo {
a,
b,
c,
d,
e,
t: fixup(t),
};
See also: