pushy
: Vec-like stack-allocated buffer pushy::PushArray
is a safe abstraction over uninitialized Rust arrays.
```rust // Fixed capacity of 3 let mut arr: PushArray<_, 3> = PushArray::new();
while let Some(elem) = rx.next() {
// push
panics if a buffer overflow would happen
arr.push(elem);
}
if let Some(elem) = otherrx.next() { // Non-panicking version of `push arr.pushchecked(elem)?; } ```
```rust
let mut arr: PushArray
// Nothing was initialized yet assert_eq!(arr.len(), 0);
arr.pushstr("World")?; asserteq!(arr.len(), 5); ```
``rust
//
asstrand
pushstrare implemented for
PushArray
// Converts to &str if the contents of the array are valid UTF-8 asserteq!(arr.asstr(), Some("Hey")); ```
```rust
let mut arr: PushArray
asserteq!(arr.get(0), Some(&b'H')); asserteq!(arr.get(1), Some(&b'e')); assert_eq!(arr.get(2), Some(&b'y'));
// Even though the capacity is 10, only three elements were initialized, so get(3)
returns None
assert_eq!(arr.get(3), None);
// Access through the Index trait assert_eq!(arr[2], b'y'); ```
```rust
let mut bytes: PushArray
let hello = [b'H', b'e', b'l', b'l', b'o']; // You can copy from a slice (currently only for Copy types) bytes.copyfromslice(&hello)?;
asserteq!(bytes.asstr(), Some("Hello"));
// Push an array onto the PushArray taking ownership of these elements (works for !Copy elements) bytes.push_array(hello)?;
asserteq!(bytes.asstr(), Some("HelloHello")); ```
```rust
let mut numbers: PushArray
// Get all initialized elements with initialized
asserteq!(numbers.initialized(), &[2, 5, 7, 2, 3, 4]);
// as_slice
is an alias to initialized
asserteq!(numbers.as_slice(), &[2, 5, 7, 2, 3, 4]);
```