$ show neo4j-labs/neo4rs
This repository is neo4rs, a production-grade asynchronous Rust driver for the Neo4j graph database. It implements the Bolt binary protocol (versions 4.x with partial 5.x support) and provides a complete client library for querying, transaction management, connection pooling, cluster routing, and serialization of Neo4j's rich data types (nodes, relationships, paths, temporal and spatial values). The architecture is modular: a connection layer handles TCP/TLS handshakes and chunked message framing; a PackStream serializer/deserializer converts between Rust types and the Bolt wire format; a routing module manages cluster membership and load balancing; and a high-level API (Graph, Session, Txn, RowStream) offers async query execution with automatic retry on transient errors. The codebase includes two parallel Bolt protocol implementationsβa legacy one and a newer feature-gated versionβwhich introduces maintenance overhead. Despite this, the project is actively maintained with extensive integration tests against multiple Neo4j versions and a robust CI pipeline. The library is suitable for any Rust application that needs to interact with Neo4j, offering both a high-level ergonomic API and low-level control over the protocol.
The LLM identified 5 files worth highlighting for reuse:
Provides the `BoltStruct` derive macro that auto-generates PackStream encoding and decoding for any Rust struct annotated with `#[signature]`. The macro implements traits for parsing from a byte stream and writing as a Bolt struct with a type marker. This pattern is reusable for any binary protocol requiring struct-level type tagging and can be extracted independently.
A generic concurrent hash map built on `RwLock<HashMap>`, offering safe asynchronous read and write operations via closures (`with_read`, `with_write`). Includes an `insert_or_update` method for atomic upserts. This component is self-contained and can be extracted for any async Rust project needing a thread-safe map without external dependencies.
Implements the `AsMap` trait and `AsMapSerializer` which force any serializable Rust value to be serialized as a PackStream map. This is used for structs and tuples that should appear as maps on the wire. The pattern is reusable for any binary serialization format that needs to control the structure of the output beyond serde's default behavior.
Defines the `ElementData` trait and `ElementDataDeserializer` that provide a uniform interface for deserializing graph elements (Node, Relation, Path) by extracting common fields like `Id`, `Labels`, `Properties`. This abstraction reduces code duplication across element-specific deserializers and can be reused for any entity with similar structural components.
Defines the `Retry` enum and `Neo4jErrorKind` to classify errors (Client, Transient, Database) and determine retryability. The pattern separates error representation from retry policy, enabling reusable retry logic for any database driver or external service. The component is self-contained and uses only standard library types.