So I have something like this:
let v = vec![...];
let s = Data { vec: &v, ... };
Perhaps this is misguided, but the idea is that many data structures could share the same vector. But for the case where I don't want to share, it would be convenient to have something like this:
let (v, s) = make_data(...);
Apparently, unlike the first example, there is no way to connect the lifetime of v and s (correct me if I'm wrong). Anyway, I understand the borrow checker rejects this. So I end up doing:
let v = vec![];
let s = make_data(&v, ...);
Now, perhaps, I could make one of those work:
let (v, s) = make_data!(...);
let s = make_data!(v, ...);
let s = make_data!(...);
The problem here is that thse macros would expand to something like { let v = vec![]; ... } and v's destructor will be run in the end of this block, but what I really want is to have it expand to something like the first example.
Now, I can make this work:
make_data!(v, s, ...);
But it's odd. Is there any other way to solve this?
(Vec<T>, &[T]). The reference is embedded inside a data structure. I can, of course, first create the vector, then create the structure, like shown in the first and third examples -- but in some cases I want to create the two with a single statement. – darque Jun 28 '15 at 19:03