vec 0.2.1 vec: ^0.2.1 copied to clipboard
A zero cost growable vector type
Vec #
A zero cost extension type of List
, representing a contiguous growable array. Unlike List
which is growable or non-growable.
Vec
is built on rust_core and is a nice compliment to its Arr
(array) type.
Usage #
import 'package:vec/vec.dart';
void main() {
Vec<int> vec = Vec(); // or e.g. Vec([1, 2, 3, 4])
List<int> list = vec.list; // easily translate back and forth
Vec<int> vec = Vec(list);
vec.push(5);
vec.insert(2, 99);
int removed = vec.remove(1);
vec.resize(10, 0);
vec.forEach((element) {
print(element);
});
// Use custom iterator to extract elements based on a condition
var iterator = vec.extractIf((element) => element % 2 == 0);
iterator.forEach((element) {
print('Extracted: $element');
});
Vec<T> spliced = vec.splice(start, end, replaceWith);
Slice<T> slice = vec.asSlice();
}