| Crates.io | vec_historic |
| lib.rs | vec_historic |
| version | 0.1.9 |
| created_at | 2025-07-17 20:48:49.234339+00 |
| updated_at | 2025-12-01 17:17:18.554977+00 |
| description | Rust Undo Collection |
| homepage | https://github.com/executable1210/vec-historic |
| repository | https://github.com/executable1210/vec-historic |
| max_upload_size | |
| id | 1758091 |
| size | 41,680 |
vec_historic is a Rust collection that extends GapBuffer(a data structure that enables efficient insertions and deletions near a cursor position by keeping a movable empty region (the "gap") inside a contiguous array.) with history tracking, undo support, and element selection.
It's especially useful for implementing editor-like data structures, timelines, or interactive data buffers.
push_back, push_front, insert, etc.)*_historic versions (e.g. insert_historic, remove_selects_historic)undo() support to revert the last operationGapBuffer for fast middle insertionsuse vec_historic::VecHistoric;
use vec_historic::vec_historic;
fn main() {
let mut b: VecHistoric<i32> = vec_historic![1, 2, 3, 4, 5, 6, 7, 8, 9];
b.insert_many_historic(5, [1996, 2004]); // 1, 2, 3, 4, 5, 1996, 2004, 6, 7, 8, 9
b.undo(); // 1, 2, 3, 4, 5, 6, 7, 8, 9
b.push_back_historic(1996); // 1, 2, 3, 4, 5, 6, 7, 8, 9, 1996
b.push_back_historic(2004); // 1, 2, 3, 4, 5, 6, 7, 8, 9, 1996, 2004
b.undo(); // 1, 2, 3, 4, 5, 6, 7, 8, 9, 1996
b.undo(); // 1, 2, 3, 4, 5, 6, 7, 8, 9
}
use vec_historic::VecHistoric;
use vec_historic::vec_historic;
fn main() {
let mut b: VecHistoric<i32> = vec_historic![1, 2, 3, 4, 5, 6, 7, 8, 9];
// Select first three elements
b.select(0);
b.select(1);
b.select(2);
// Remove selected elements from the collection and push the action in history sequence
let removed: &Vec<i32> = b.remove_selects_historic(); // Returns address of removed elements -> [0, 1, 2]
println!("{:?}", b); // [3, 4, 5, 6, 7, 8, 9]
b.undo();
// Undone elements are selected [0, 1, 2]
println!("{:?}", b); // [1, 2, 3, 4, 5, 6, 7, 8, 9]
b.deselect_all(); // deselect all elements
}