| Crates.io | the-zipper |
| lib.rs | the-zipper |
| version | 0.1.3 |
| created_at | 2025-04-07 11:52:04.666627+00 |
| updated_at | 2025-04-15 12:44:15.902566+00 |
| description | The zipper is a data structure that allows you to traverse and modify a tree-like structure efficiently. It provides a way to navigate through the tree while keeping track of the context, enabling functional programming techniques. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1624022 |
| size | 58,923 |
The Zipper is a Rust library designed to provide efficient and ergonomic utilities for working with data structures using the zipper pattern. This library simplifies navigation and modification of complex data structures while maintaining immutability.
HUET G. The Zipper. Journal of Functional Programming. 1997;7(5):549-554. doi:10.1017/S0956796897002864
Add the following to your Cargo.toml:
[dependencies]
the_zipper = "0.1.2"
use the_zipper::Location;
fn main() {
let tree = Tree::Section(vec![Tree::Item("a"), Tree::Item("+"), Tree::Item("b")]);
let location = Location::new(tree);
let location = location.go_down().unwrap();
assert_eq!(location.cursor, Tree::Item("a"));
let location = location.go_right().unwrap();
assert_eq!(location.cursor, Tree::Item("+"));
let location = location.go_left().unwrap();
assert_eq!(location.cursor, Tree::Item("a"));
let location = location.insert_right(Tree::Item(".")).unwrap();
assert_eq!(
location,
Location {
cursor: Tree::Item("a"),
path: Path::Node {
left: vec![],
right: vec![Tree::Item("."), Tree::Item("+"), Tree::Item("b")],
path: Path::Node {
left: vec![],
right: vec![Tree::Section(vec![
Tree::Item("a"),
Tree::Item("+"),
Tree::Item("b")
])],
path: Path::Top.into()
}
.into()
}
.into()
}
.into()
);
}
This project is licensed under the MIT License. See the LICENSE file for details.