Skip to content

Expose unsafe into_parts and from_parts functions #54

@Bahex

Description

@Bahex

Expose a way to decompose EcoVec into its components, similar to Vec::into_parts and Vec::from_parts (which are, as of now, nightly only).

This is useful for struct-of-array patterns where multiple vectors always have identical lengths, but might be cloned or mutated separately.

struct SoA {
    foo: EcoVec<Foo>,
    bar: EcoVec<Foo>,
    baz: EcoVec<Baz>,
    qux: EcoVec<Qux>,
}

// [usize; 2 * N] size for N items
assert!(std::mem::size_of::<SoA>() == [usize; 8]);

Providing a way to decompose and recompose EcoVec would make such structs significantly smaller:

struct SoA {
    foo: EcoVecRaw<Foo>,
    bar: EcoVecRaw<Foo>,
    baz: EcoVecRaw<Baz>,
    qux: EcoVecRaw<Qux>,
    len: usize,
}

// [usize; N + 1] size for N items
assert!(std::mem::size_of::<SoA>() == [usize; 5]);

Methods of SoA would recompose the relevant EcoVecRaw (or whatever it ends up being named) with len as necessary to get back an EcoVec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions