$ show influxdb-rs/influxdb-rust
This is a Rust library providing an async client for InfluxDB 1.x and 2.x (compatibility mode). It supports writing and reading data via the InfluxDB HTTP API, with a fluent query builder for constructing line protocol write queries and read queries. The library offers optional serde integration for deserializing query results into Rust structs using a custom Serde deserializer that handles InfluxDB's column/value array format. It also includes a derive macro (`InfluxDbWriteable`) for automatically generating write queries from structs. The architecture is centred around a `Client` struct that wraps a `reqwest` HTTP client, with support for authentication (basic auth and token-based) and multiple HTTP backends via feature flags. The codebase is well-structured, with clean separation of concerns, extensive unit and integration tests, and a strong emphasis on correct line protocol escaping. The custom serde deserializer is a notable highlight, demonstrating advanced Serde patterns for transforming array-of-arrays into map-like structures. The project is actively maintained with recent commits and a clear release process.
The LLM identified 3 files worth highlighting for reuse:
Implements a custom Serde deserializer that transforms InfluxDB's column/value array format into Rust structs. It uses a `HeaderVec` seed and `RowWithHeader` pattern to map array indices to column names, enabling struct deserialization from JSON arrays. This pattern is reusable for any data format where columns and values are separate arrays, and demonstrates advanced Serde `DeserializeSeed` and `MapAccess` usage.
Provides line protocol escaping for measurement names, tag keys/values, and field keys/values. Uses static regexes to escape special characters (commas, spaces, equals, quotes, backslashes) according to InfluxDB specification. Includes both v1 and v2 escaping modes for unsigned integer notation. This component is self-contained and could be extracted into a standalone library for InfluxDB line protocol generation.
Builds InfluxDB line protocol write queries using a fluent builder pattern. Defines a `Type` enum with conversions from standard Rust types via a macro, supports optional fields via `Option<T>`, and batch writing via `Vec<WriteQuery>`. The builder enforces that at least one field is added before building. The escaping integration is clean. This is a well-crafted example of a type-safe query builder that could serve as a template for other similar builders.