Is there syntax for moving fields between similar structs?

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:

Leave a Comment