News for hackers. Stuff that matters.
Re:Rust Language Cheat Sheet by masklinn on Monday April 26, 2021 @01:32AM (#26939513)
> Well, the backing array knows its length and capacity

arrays don’t have capacity. The capacity of a slice is the length of its backing array (minus the offset of the slice in the array, which is why slices do need to store a cap separately).

> it's quite trivial to see that there are elements in the array beyond the length of the slice.

There are always elements in the array beyond the length of the slice (unless the slice is « at capacity »).

> EDIT: I'm shocked and appalled by the fact that you're completely right. https://play.golang.org/p/UZSlBMUlc_E

Yup. Go slices are fun. And by fun I mean error-prone.

Well most of the trouble really comes from them having double-duty as actual slices and add-hoc pseudo vectors.

There are no comments on this comment yet.