Skip to content

Packed Arrays could use some more trait impls #663

Open
@lilizoey

Description

@lilizoey

For instance, you cannot currently do

let v = vec![Vector3::new(1.0, 2.0, 3.0)];
let packed: PackedVector3Array = v.into();

This could be fixed with a From<Vec<Vector3>> impl for PackedVector3Array.

In general since packed arrays are very similar to Vec we could also take inspiration from what Vec has implemented.

See discussion below for more details.

Traits to implement:

  • From<Vec<T>>
  • From<[T; N]>
  • From<Array<T>>
  • From<PackedTArray> for Array<T>
  • Index and IndexMut, i think we can use I: SliceIndex like Vec does.
  • IntoIterator
  • Write, for PackedByteArray only but preferably have a use-case first

Other trait impls we can consider:

  • Deref and DerefMut to [T]. may conflict with Godot's api for packed arrays
  • From<Box<[T]>>, From<VecDeque<T>>. We can already do this with collect()
  • AsRef<[T]>, AsMut<[T]>, Borrow<[T]>, BorrowMut<[T]>. Should have a use-case first

Additionally we apparently have From<&VariantArray> for PackedVector3Array etc, which is wrong. (looking at the implementation this might actually be UB).

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: coreCore componentsgood first issueGood for newcomersquality-of-lifeNo new functionality, but improves ergonomics/internals

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions