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

Does not support generics.

Open entropylost opened this issue 4 years ago • 6 comments

If I have something like:

struct Foo<T: S> {
  x: T
}

the derive command causes errors.

entropylost avatar May 27 '21 01:05 entropylost

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.

Luthaf avatar May 27 '21 08:05 Luthaf

My god this looks like so much work...

entropylost avatar May 28 '21 00:05 entropylost

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).

mangelats avatar May 28 '21 01:05 mangelats

Hm for the single length thing perhaps just make the storage generic and use a HList?

entropylost avatar May 28 '21 02:05 entropylost

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!

Luthaf avatar May 28 '21 08:05 Luthaf

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.

entropylost avatar May 28 '21 16:05 entropylost