fizyk20/generic-array

API style documentation?

Closed this issue · 3 comments

(Please be advised, I am a beginner with Rust.)

I am trying to use GenericArray to implement a dynamically sized array. I am having a hard time understanding how to use GenericArray for things like:

  • Creating a new, empty array
  • Inserting new items into the array
  • Getting the length (number of items currently inside) of the array
  • Getting the size/capacity of the array as defined by ArrayLength

The design document has helped a bit but I feel pretty lost when looking at the documentation. Is there a simple way for me to understand what methods I can use with GenericArray?

Thank you for your patience with me in advance!

GenericArray is for fixed-size arrays. It does not support dynamic insertion or removal of elements.

You may want to check out SmallVec instead if you need stack-allocated arrays with dynamic size, otherwise I'd recommend just using a regular Vec

@novacrazy thanks for the reply. I am trying to use it to model my own version of what Vec does, or generally how a dynamic size array works. So, I don't GenericArray to be resizable. Looking back at my post I realize that wasn't clear.

I just aim to understand how I can use GenericArray and what methods are available for it.

I apologize for abandoning this issue.

What you were trying to do did not seem to be relevant to GenericArray.

GenericArray<T, N> is simply a way of achieving [T; N] on stable Rust. It's more or less a hack. The DESIGN.md document goes into how GenericArray works, if you are still curious. It cannot be dynamically resized and would not be useful in creating a Vec from scratch.

Feel free to reopen this if you still require assistance.