soa-derive icon indicating copy to clipboard operation
soa-derive copied to clipboard

Implement Extend for Vec

Open schneiderfelipe opened this issue 4 months ago • 1 comments

I would like to implement Extend<&'a #name> for #vec_name as well (just like std::vec::Vec<T>), but I would have to make sure #name is Copy (where #name: Copy does not help).

This is not the most performant implementation either, but it works.

Fix #51.

schneiderfelipe avatar Feb 23 '24 20:02 schneiderfelipe

I would like to implement Extend<&'a #name> for #vec_name

Maybe you can use the same kind of trick with higher-rank bounds as to_owned? https://github.com/lumol-org/soa-derive/blob/f41eecb4298030f52d703a71aa003bad15952f8a/soa-derive-internal/src/refs.rs#L150-L153

It would only check if all fields are copy and not the full struct, but this should be close enough.

Luthaf avatar Feb 24 '24 11:02 Luthaf

I would like to implement Extend<&'a #name> for #vec_name

Maybe you can use the same kind of trick with higher-rank bounds as to_owned?

https://github.com/lumol-org/soa-derive/blob/f41eecb4298030f52d703a71aa003bad15952f8a/soa-derive-internal/src/refs.rs#L150-L153

It would only check if all fields are copy and not the full struct, but this should be close enough.

This did the trick. Now we have both impl Extend<#name> for #vec_name and impl<'a> Extend<#ref_name<'a>> for #vec_name, the last one only available if all fields are Clone, so that to_owned can be called. This matches the available implementations on Vec<T>, impl<T, A> Extend<T> for Vec<T, A> and impl<'a, T, A> Extend<&'a T> for Vec<T, A>.

schneiderfelipe avatar May 14 '24 15:05 schneiderfelipe