I expected something like the following to work:
struct Foo<A, B, C> {
a: A,
b: B,
// Assume there's a bunch more fields here so this would be a pain to copy
// when you're just changing one type
}
impl<A, B, C> Foo<A, B, C> {
fn update_b<B_>(self, b: B_) -> Foo<A, B_> {
Foo { b: b, .. self }
}
}
However, I get a mismatched types error:
<anon>:8:24: 8:28 error: mismatched types:
expected `Foo<_, B_>`,
found `Foo<A, B>`
(expected type parameter,
found a different type parameter) [E0308]
<anon>:8 Foo { b: b, .. self }
^~~~
<anon>:8:24: 8:28 help: see the detailed explanation for E0308
I understand the problem, I was just hoping that the record update syntax would have been able to transform the type so I didn’t have to copy all the fields by hand.
Is this trivial to implement in the language? It would be forward-compatible AFAICT.