What is the relationship between reference of tuple and tuple of reference as types?
Why does the first works but the second doesn't?
let a = 1;
let b = 2;
// This works, c: &i32, d:&i32
let (c, d) = &(a, b);
type TupleOfRef<'a> = (&'a i32, &'a i32);
let e = (a, b);
// This doesn't
let f: TupleOfRef = &e;
To make my point of question more clear. It is more about the relation of type (&'a A, &'a B)
with (A, B)
.
Thought the memory layout of tuple is not guaranteed, it is clear that can't make &(A, B)
out of &A
and &B
without cloning, since there is no one memory address holding A
and B
.
However, making (&A, &B)
out of (A, B)
makes some sense, since we have not only the address of tuple, (namely, &(A, B)
), but also at the addresses of its elements, (namely, &A
and &B
, as @etchesketch mentioned). And this seems work in the first case of the example above, but not in the second.
Actually the second is what I want. Is there anyway to (&A, &B, ..)
out of owned (A, B, ..)
in general? Or is there any good way to express these 'matchability' in trait bound?
Following question: Tuple of Reference and Reference of Tuple for type level operation