{"id":18359224,"url":"https://github.com/rust-scraper/ego-tree","last_synced_at":"2026-01-23T22:28:30.133Z","repository":{"id":54766396,"uuid":"48984285","full_name":"rust-scraper/ego-tree","owner":"rust-scraper","description":"Vec-backed ID-tree","archived":false,"fork":false,"pushed_at":"2026-01-15T20:10:36.000Z","size":903,"stargazers_count":70,"open_issues_count":0,"forks_count":24,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-15T22:32:57.338Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.rs/ego-tree","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-scraper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-01-04T08:32:35.000Z","updated_at":"2026-01-15T20:10:42.000Z","dependencies_parsed_at":"2024-12-08T06:02:44.008Z","dependency_job_id":"5bd51888-39ef-446c-a544-9645c58de961","html_url":"https://github.com/rust-scraper/ego-tree","commit_stats":{"total_commits":168,"total_committers":13,"mean_commits":"12.923076923076923","dds":0.375,"last_synced_commit":"95aaf8b66a78986b31b7924be5a2e9bda4395023"},"previous_names":["programble/ego-tree","rust-scraper/ego-tree","causal-agent/ego-tree"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/rust-scraper/ego-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-scraper%2Fego-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-scraper%2Fego-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-scraper%2Fego-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-scraper%2Fego-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-scraper","download_url":"https://codeload.github.com/rust-scraper/ego-tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-scraper%2Fego-tree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28701676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T22:21:37.172Z","updated_at":"2026-01-23T22:28:30.118Z","avatar_url":"https://github.com/rust-scraper.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ego Tree\n\n[![crates.io](https://img.shields.io/crates/v/ego-tree?color=dark-green)][crate]\n[![downloads](https://img.shields.io/crates/d/ego-tree)][crate]\n[![test](https://github.com/rust-scraper/ego-tree/actions/workflows/test.yml/badge.svg)][tests]\n\n`ego-tree` is a Rust crate that provides a Vec-backed ID-tree implementation. It offers a flexible and efficient way to create and manipulate tree structures in Rust, with a focus on performance and ease of use.\n\n`ego-tree` is on [Crates.io][crate] and [GitHub][github].\n\n## Design Philosophy\n\nThe design of `ego-tree` is centered around the following principles:\n\n1. **Efficiency**: The tree structure is backed by a Vec, allowing for fast, cache-friendly operations and efficient memory usage.\n\n2. **Flexibility**: Nodes can have any number of children, allowing for the representation of various tree structures.\n\n3. **Stability**: Node references remain valid even after modifying the tree structure, thanks to the use of stable NodeId indices.\n\n4. **Safety**: The API is designed to prevent common errors, such as creating cycles or detaching the root node.\n\n5. **Ergonomics**: The crate provides both low-level operations and high-level conveniences like the `tree!` macro for easy tree construction.\n\n## Key Design Choices\n\n### Vec-Backed Structure\n\nUnlike traditional pointer-based trees, `ego-tree` uses a Vec to store all nodes. This design choice offers several advantages:\n\n- Improved cache locality, potentially leading to better performance\n- Simplified memory management\n- Easier serialization and deserialization\n- Constant-time access to any node by its ID\n\n### Node IDs\n\nNodes are identified by `NodeId`s, which are wrappers around indices into the underlying Vec. This approach allows for:\n\n- Stable references to nodes, even as the tree structure changes\n- Efficient node lookup (O(1) time complexity)\n- Compact representation of relationships between nodes\n\n### Immutable and Mutable Node References\n\nThe crate provides both `NodeRef` (immutable) and `NodeMut` (mutable) types for working with nodes. This separation allows for:\n\n- Clear distinction between read-only and modifying operations\n- Prevention of multiple mutable references to the same node, enforcing Rust's borrowing rules\n- Efficient implementation of various tree traversal iterators\n\n### Orphan Nodes\n\nNodes can be detached from the tree but not removed entirely. This design choice:\n\n- Simplifies certain tree manipulation algorithms\n- Allows for temporary detachment and reattachment of subtrees\n- Maintains the validity of NodeIds, even for detached nodes\n\n### Rich Iterator Support\n\nThe crate provides a variety of iterator types for traversing the tree in different ways. This design:\n\n- Allows for efficient and idiomatic tree traversal\n- Supports various algorithms and use cases without sacrificing performance\n- Leverages Rust's powerful iterator ecosystem\n\n## Use Cases\n\n`ego-tree` is well-suited for applications that require:\n\n- Efficient representation and manipulation of hierarchical data structures\n- Frequent traversal and modification of tree structures\n- Stable references to tree nodes across operations\n- Serialization and deserialization of tree structures\n\nSome potential use cases include:\n\n- DOM-like structures for document processing\n- File system representations\n- Organizational hierarchies\n- Game scene graphs\n- Abstract syntax trees for compilers or interpreters\n\n## Getting Started\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nego-tree = \"0.6.2\"\n```\n\nBasic usage:\n\n```rust\nuse ego_tree::Tree;\n\nlet mut tree = Tree::new(1);\nlet mut root = tree.root_mut();\nroot.append(2);\nlet mut child = root.append(3);\nchild.append(4);\nchild.append(5);\n```\n\nFor more detailed usage examples and API documentation, please refer to the [documentation](https://docs.rs/ego-tree).\n\n## License\n\nThis project is licensed under the ISC License.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Credits\n\n`ego-tree` is created and maintained by the team of [rust-scraper](https://github.com/rust-scraper).\n\n[crate]: https://crates.io/crates/ego-tree\n[github]: https://github.com/rust-scraper/ego-tree\n[tests]: https://github.com/rust-scraper/ego-tree/actions/workflows/test.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-scraper%2Fego-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-scraper%2Fego-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-scraper%2Fego-tree/lists"}