soa-derive
soa-derive copied to clipboard
Implement Extend for Vec
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.
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.
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>
.