Rc<Vec<T>> vs Rc<&[T]>
Is one always better than the other, or are there separate cases where each shines ?
Rc<Vec<T>> vs Rc<&[T]>
Is one always better than the other, or are there separate cases where each shines ?
Shared references are Copy
, and I don't think it ever makes sense to reference-count a Copy
type. (Reference-counting a non-'static
type doesn't make much sense either.)
Both are inferior to Rc<[T]>
, AFAIK, since the only difference between Vec
and slice is that vector is growable (which is impossible anyway inside Rc
), and Rc<&Something>
is, well, somewhat redundant, as both Rc
and reference are instruments for sharing data.
Rc<Vec<T>>
can be useful if you want to avoid copying from Vec<T>
or want some CoW without borrowing. Rc::make_mut()
is a handy function for the latter.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.