Visitor Pattern over Traversable Data Structures in Rust
Overview
This crate provides traits and proc macros to implement the visitor pattern for arbitrary data structures. This pattern is particularly useful when dealing with complex nested data structures, abstract trees and hierarchies of all kinds.
Quick Start
Add traversable to your Cargo.toml with the derive feature:
[]
= { = "0.2", = ["derive", "std"] }
Define your data structures and derive Traversable:
use Any;
use ControlFlow;
use Traversable;
use Visitor;
Attributes
The derive macro supports the following attributes on fields and variants:
#[traverse(skip)]: Skips traversing into the annotated field or variant.#[traverse(with = "function_name")]: Uses a custom function to traverse the field.
Minimum Rust version policy
This crate is built against the latest stable release, and its minimum supported rustc version is 1.85.0.
The policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if Traversable 1.0 requires Rust 1.60.0, then Traversable 1.0.z for all values of z will also require Rust 1.60.0 or newer. However, Traversable 1.y for y > 0 may require a newer minimum version of Rust.
License
This project is licensed under Apache License, Version 2.0.