Amanieu / intrusive-rs

Intrusive collections for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

intrusive_adapter! for ?Sized types

tower120 opened this issue · comments

I want to use intrusive_adapter! with dyn_struct's DynStruct :

type SparseComponentPtrs = DynStruct<LinkedListLink, Option<NonNull<u8>>>;
intrusive_adapter!(SparseAdapter = Box<SparseComponentPtrs>: SparseComponentPtrs { header: LinkedListLink });

But have following error:

error[E0599]: the function or associated item `uninit` exists for union `MaybeUninit<DynStruct<LinkedListLink, Option<NonNull<u8>>>>`, but its trait bounds were not satisfied
  --> crates\ecs_rs\src\component_archetype_cache.rs:25:1
   |
25 | intrusive_adapter!(SparseAdapter = Box<DynStruct<LinkedListLink, Option<NonNull<u8>>>>: DynStruct<LinkedListLink, Option<NonNull<u8>>> { header: LinkedListLink ...
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item cannot be called on `MaybeUninit<DynStruct<LinkedListLink, Option<NonNull<u8>>>>` due to unsatisfied trait bounds
   |
  ::: C:\Users\Andy\.cargo\registry\src\github.com-1ecc6299db9ec823\dyn_struct-0.2.0\src\lib.rs:96:1
   |
96 | pub struct DynStruct<Header, Tail> {
   | ---------------------------------- doesn't satisfy `_: Sized`
   |
   = note: the following trait bounds were not satisfied:
           `DynStruct<LinkedListLink, Option<NonNull<u8>>>: Sized`
   = note: this error originates in the macro `_memoffset__let_base_ptr` (in Nightly builds, run with -Z macro-backtrace for more info)

Can I do something about this?

You can try implementing the Adapter trait manually instead of using the macro. The reason it doesn't work is that memoffset doesn't support unsized types since those don't have a fixed layout at compile-time.

I see, thanks!