Skip to content

Allow array indexing #390

Description

@schoen

Project

core

Describe the feature

Maybe this is tricky in terms of the type system, but I think it would be great to able to do

let a: [u8; 4] = [0, 17, 255, 23];
let b: u8 = a[3];

and similar. Right now you have to actually destructure the whole array in order to get individual values. For example, p2ms.simf does

    let [pk1, pk2, pk3]: [Pubkey; 3] = pks;
    let [sig1, sig2, sig3]: [Option<Signature>; 3] = maybe_sigs;

and you can't conveniently refer to the value at position i at all. I don't think there is an architectural reason that this is meant to be prohibited.

(Among other things, this means that it's hard-to-impossible to loop over an array with for_while, although you can differently loop over an array with array_fold.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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