soa-derive
soa-derive copied to clipboard
Does not support generics.
If I have something like:
struct Foo<T: S> {
x: T
}
the derive command causes errors.
Yes, that's something that would be nice to implement, and should not be too hard. Unfortunately, I have very limited time to work on this crate, so this would be a good candidate for an external contribution!
It should only be a matter of storing the generic parameters and bounds in the Input struct; and then parametrize the generated structs (slice, mut slice, reference, mut reference, pointer, mut pointer, ...) by the same generic parameters and bounds. The impl blocks should also be parametrized by the same generics parameters & bounds.
My god this looks like so much work...
To be honest I'd love to work on it. Unfortunately right now I don't really have the time for it (and single length would come first anyways). I'd love to talk about project reorganization to code this features more easier (the more advanced the features the more I tend to hurt myself with it).
Hm for the single length thing perhaps just make the storage generic and use a HList?
Hm for the single length thing perhaps just make the storage generic and use a HList?
I really don't see how a HList would help here, could you clarify?
EDIT: moved the discussion to https://github.com/lumol-org/soa-derive/issues/19#issuecomment-850638812
I'd love to talk about project reorganization to code this features more easier (the more advanced the features the more I tend to hurt myself with it).
I'm open to changes in this crate code organization: while none of the code is very complex, it can be a bit daunting to make changes, and the compiler error messages are not very helpful when you make a typo/miss a bound somewhere. Please open an issue with your proposition!
So for using a HList, your #[derive(StructOfArray)] would effectively create this:
struct Foo {
x: i32,
y: String,
}
impl From<HList<String, HList<i32, HNil>> for Foo
impl From<Foo> for HList<String, HList<i32, HNil>>
then the vector type would simply be something like this:
struct SOAStorage<T: Into<HList...> + From<HList...>> {
vec: Vec<T::Head>
next: SOAStorage<T::Tail>
}
(Or something like this, this doesn't compile but you probably get the point right?)
But this way you only need to implement a single trait and then just use SOAStorage<Foo> for all other cases. Also supports having custom storages like one that stores length once.