-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Abstract
Manipulating data vectors is common in Move packages. A fundamental operation is the ability to retrieve a slice of a vector in the range of [start; end[
.
A particular use case is when handling a vector of u8 (a.k.a bytes). Currently, a developer must copy the bytes one by one from the original vector to a new one to create the slice. This is far from efficient, as it involves performing a number of read, copy, and write operations equal to the length of the slice range.
Solution proposed
To address this, I propose implementing a new native function, public native fun vector::copy_slice<T: copy>(v: &vector<T>, start: u64, end: u64): vector<T>
. Constraining T
to have the copy
ability is mandatory to ensure that no Move rule is violated when copying the data into a slice.
As a native function, it would take advantage of the Rust runtime to read the container, copy the values once, and return them as a vector<T>
.
If you agree with this idea, I can work on it and submit a PR 🙏
(cc @damirka)