Skip to content

Collaboration proposal #1

@WalterSmuts

Description

@WalterSmuts

I like your idea! And the name! (hence why I'm asking to collaborate rather than publishing my own crate).

How do you feel about trying to make this api a bit closer to the normal slicing API?

let sub_slice = &slice[1..2]

I've played around a bit and the closest I can get is this:

let sub_array: &[u32; 2] = &array[range!(1, 2)];

I think with a little extra proc_macro trickery we may be able to get to the following:

let sub_array: &[u32; 2] = &array[range!(1..2)];

The main value I believe this crate would bring is to provide a safe API for doing sub-array slicing on arrays. You can enforce the safety via compile time constraints using trait bounds. This is unfortunately not possible using slices, so I would also propose the API on slices get removed. It feels a bit strange to have it in a crate with the word array in anyway.

There definitely are some disadvantages of doing what I'm suggesting. The main one is that it requires generic_const_exprs feature to do the trait bound constraints, which is still unstable. This means the consumers of this library need to use the nightly compiler until it get stabilised.

Have a look at this playground to get an idea of what I'm suggesting.

The main thing you may notice where I've gone in a separate direction from you is the use of the SubArray wrapper struct. This is to allow overloading of the Index trait. I'm not married to the idea, but I do think it has some advantages.

Let me know what you think! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions