im-rc::Vector<u8> to Vec<u8>

fn (im_vec: ImVec<u8>) {
  let mut y = vec![];
  for x in im_vec.iter() {
    y.push(*x);
  }

The above works, but looks verbose. I would like to try:

im_vec.iter().collect::<Vec<_>>()

but the issue is that it generates Vec<&u8> instead of a Vec<u8>

What is the cleanest way to do ImVec<u8> to Vec<u8> ?

EDIT:

ImVec refers to im-rc::Vector

im_vec.iter().copied().collect::<Vec<_>>()

2 Likes

to avoid reallocations you could use let mut y = Vec::with_capacity(im_vec.len());, though apparently the iterator syntax does the same in some cases