2 ms·
Minor nit: >ByteString represents a byte buffer and its associated length; in this it is similar to Go’s []byte or Rust’s &[u8] (though it has one fewer datum
by Arnavion 5y ago
Minor nit:
>ByteString represents a byte buffer and its associated length; in this it is similar to Go’s []byte or Rust’s &[u8] (though it has one fewer datum to track, as the Rust and Go types offer mutable access to the associated byte buffer and thus must keep track of its total capacity).
Rust's &[u8] and &mut [u8] don't track capacity. Mutable access only allows changing the data in the slice, not changing its length. It couldn't even if it wanted to, since it has no idea of what the underlying storage is. It's only Go's slices that do double-duty as a ranged view into an existing allocation but also with the freedom to become the owner of a new allocation.
- bennofs 5y agoHow does rust do bounds checking for slice accesses if the length is not stored?
- steveklabnik 5y agoLength and capacity are two different things; a slice is a pointer and a length, but a Vec<T> (and Go's slices) are a pointer, a length, and a capacity. That Rust and Go both have "slices" that are slightly different is, unfortunate, but that's just how it goes sometimes.