Expand description
§Babbel
A unified, high-performance polyglot serialization and document processing ecosystem.
Provides first-class support for JSON, YAML, XML, BitTorrent Bencode, RFC 4180 CSV/TSV,
sectioned INI/.env, and JSON Lines, backed by a shared core (babbel_core).
§Sub-libraries & Modules
core: Common streaming I/O (ILineReader), universalValueAST, BOM detection, and numeric utilities.json: Full-featured JSON DOM, JSON Pointer (RFC 6901), Merge Patch (RFC 7396), and JSON Lines streaming.yaml: YAML 1.2 parser/emitter with anchors, aliases, tags, and multi-document streams.xml: Validating XML parser, C14N canonicalization, and XPath 1.0 engine.bencode: Fast, binary-safe BitTorrent Bencode serializer and DOM.toml: Fast, modular, pure-Rust TOML v1.1.0 parser and serializer.msgpack: High-speed, binary-safe MessagePack encoder and decoder.cbor: RFC 8949 Concise Binary Object Representation (CBOR) encoder/decoder.bson: High-performance Binary JSON (BSON v1.1) specification encoder/decoder.ron: Rusty Object Notation (RON) parser and serializer for Rust configurations and games.kdl: KDL Document Language (KDL v2) parser and serializer for modern CLI and document configs.parquet: Apache Parquet columnar storage reader, writer, and FormatEngine for analytical data.hcl: HashiCorp Configuration Language (HCL v2) and Terraform parser and serializer.avro: Apache Avro binary and Object Container File (OCF) parser and serializer.csv: RFC 4180 CSV and TSV parsing/emission with delimiter sniffing and type inference.ini: Section-based INI, Java.properties, and.envparsing/emission.text: Document frontmatter extraction (split_frontmatter) and line indentation utilities.convert: Universal $O(N)$ cross-format conversion matrix across 16 formats.
§Architectural Data Flow
Text / Bytes ──► FormatParser ──► Universal Value AST ──► FormatEmitter ──► Destination
│ │
▼ ▼
Error Snippet Buffer / File§Universal Facade & Fluent Builders
use babbel::prelude::*;
// 1. Fluent AST construction
let config = Value::object()
.set("service", "gateway")
.set("port", 8080)
.set("features", Value::array().push("metrics").push("tracing").build())
.build();
// 2. Direct serialization across formats
let json_text = babbel::to_string(Format::Json, &config)?;
assert!(json_text.contains("\"service\":\"gateway\""));
// 3. Universal cross-format conversion
let yaml_text = babbel::convert(Format::Json, Format::Yaml, &json_text)?;
assert!(yaml_text.contains("service: gateway"));§Quickstart
#[cfg(feature = "json")]
{
let json_node = babbel::json::from_str(r#"{"service": "babbel", "port": 8080}"#)?;
assert_eq!(json_node.get("service").and_then(|n| n.as_str()), Some("babbel"));
}
// Parse CSV
let csv_val = babbel::parse_csv("name,score\nAlice,100\n", &babbel::CsvOptions::default())?;
assert_eq!(csv_val.as_array().unwrap().len(), 1);
#[cfg(feature = "convert")]
{
let yaml_str = babbel::convert::json_to_yaml(r#"{"name": "test"}"#)?;
assert!(yaml_str.contains("name: test"));
let json_str = babbel::convert::csv_to_json("id,item\n1,rust\n")?;
assert!(json_str.contains("rust"));
}Re-exports§
pub use convert::Format;pub use babbel_core as core;pub use babbel_json as json;pub use babbel_yaml as yaml;pub use babbel_xml as xml;pub use babbel_bencode as bencode;pub use babbel_toml as toml;pub use babbel_msgpack as msgpack;pub use babbel_cbor as cbor;pub use babbel_bson as bson;pub use babbel_ron as ron;pub use babbel_kdl as kdl;pub use babbel_parquet as parquet;pub use babbel_hcl as hcl;pub use babbel_avro as avro;pub use babbel_bencode as bencode_lib;pub use babbel_json as json_lib;pub use babbel_toml as toml_lib;pub use babbel_xml as xml_lib;pub use babbel_yaml as yaml_lib;
Modules§
- compression
- Zero-dependency,
no_std+alloccompression codecs (Snappy, LZ4 Raw) and CRC32. - convert
- Cross-format conversion matrix for the Babbel ecosystem.
- csv
- RFC 4180 compliant Delimited Text (CSV / TSV) parser and emitter.
- diff
- embedded
- Unified embedded systems module aggregating zero-allocation streaming parsers, stack-allocated destinations, and memory limits for microcontrollers.
- ini
- Configuration Text Engine (INI / Java .properties / .env) parser and emitter.
- macros
- Declarative macro
value!for ergonomicValueconstruction. - patch
- prelude
- Convenient prelude re-exporting key format engines, universal Value AST, I/O traits,
the declarative
value!macro, and conversion routines. - query
- schema
- serde
- Direct Serde serialization and deserialization APIs across all supported formats.
- text
- Line-oriented text processing, frontmatter extraction, hexadecimal utilities, and indentation manipulation.
- transform
- Polyglot Query & Transformation Pipeline Engine (
jq/yqstyle operators overValue).
Macros§
- value
- Constructs a
babbel_core::Valueusing literal syntax.
Structs§
- Array
Builder - Fluent builder for constructing
Value::Array. - Array
VecDestination - Stack-allocated fixed-capacity byte buffer destination using const generics.
- Avro
Engine - Format engine for Apache Avro binary payloads (
.avro). - Babbel
Error - Unified, structured error type for polyglot serialization and parsing.
- Bencode
Engine - Bencode format engine implementing
FormatEngine. - Bson
Engine - BSON format engine implementing
FormatEngine. - Cbor
Engine - CBOR format engine implementing
FormatEngine. - Compact
Error - Zero-allocation 8-byte diagnostic error for bare-metal embedded targets (
no_alloc). - Compiled
Schema - A compiled, optimized JSON Schema validator ready for zero-allocation reuse.
- CsvEngine
- Standard built-in CSV format engine implementing
FormatEngine. - CsvFields
Iter - Zero-allocation iterator over fields within a
CsvRecord. - CsvOptions
- Configuration options for delimited text (CSV / TSV) parsing and serialization.
- CsvPull
Parser - Zero-allocation streaming CSV pull parser for microcontrollers and embedded systems.
- CsvRecord
- A borrowed CSV record (row) referencing slices in the original input buffer.
- Document
With Frontmatter - Represents a parsed document containing optional frontmatter metadata and body content.
- Embedded
Limits - Runtime and compile-time limits to protect against stack overflows and excessive resource consumption.
- Format
Options - Universal format serialization options.
- Format
Options Builder - Fluent builder for
FormatOptions. - Format
Registry - Dynamic format engine registry supporting lookup by format ID, MIME type, or file extension.
- Format
Visitor Serializer - Serializer that drives a
FormatVisitordirectly from any Serde-serializable type. - HclEngine
- Format engine for HashiCorp HCL v2 (
.hcl,.tf,.tfvars). - IniEngine
- Standard built-in INI / properties / .env format engine implementing
FormatEngine. - IniOptions
- Configuration options for INI and property file parsing and emission.
- IniPull
Parser - Zero-allocation streaming INI and property file pull parser.
- Json5
Engine - JSON5 and JSONC format engine implementing
FormatEngine. - Json
Engine - JSON format engine implementing
FormatEngine. - Json
Lines Engine - JSON Lines format engine implementing
FormatEngine. - Json
Path - A compiled RFC 9535 JSONPath expression.
- KdlEngine
- KDL format engine implementing
FormatEngine. - Located
Node - A matched node paired with its RFC 9535 normalized path (
$['store']['books'][0]) and RFC 6901 JSON Pointer ("/store/books/0"). - Location
- Accurate 1-based source code location.
- Memory
Tracker - Tracks memory allocations and peak watermarks for resource-constrained environments.
- MsgPack
Engine - MessagePack format engine implementing
FormatEngine. - Object
Builder - Fluent builder for constructing
Value::Object. - Parquet
Engine - Apache Parquet format engine implementing
FormatEngine. - Parse
Options - Universal configuration options for parsing.
- Patch
- An ordered sequence of RFC 6902 patch operations.
- Regex
- A compiled regular expression AST.
- RonEngine
- RON format engine implementing
FormatEngine. - Schema
Validation Error - Structured validation error containing pointer location, failed keyword, and error description.
- Serde
Error - Error type for Serde conversions with
Value. - Slice
Destination - Zero-allocation in-memory destination writing directly into a caller-supplied byte slice.
- Span
- Source code span identifying start and end locations.
- Stack
Buffer - Fixed-size stack-allocated byte buffer using const generics.
- Toml
Engine - TOML format engine implementing
FormatEngine. - TsvEngine
- Standard built-in TSV format engine implementing
FormatEngine. - XmlEngine
- XML format engine implementing
FormatEngine. - Yaml
Engine - YAML format engine implementing
FormatEngine.
Enums§
- Duplicate
KeyMode - Strategy for handling duplicate keys during object / mapping parsing.
- Error
Code - Standardized diagnostic error codes across format parsers, encoders, and validators.
- Frontmatter
Format - Supported frontmatter header formats.
- IniEvent
- Streaming event emitted by
IniPullParser. - PatchOp
- A single RFC 6902 patch operation.
- Value
- Universal hierarchical data value across XML, JSON, YAML, and Bencode representations.
Traits§
- Format
Codec - A combined format codec providing both parsing and emission capabilities.
- Format
Emitter - Abstract emitter writing a universal
ValueAST to an output destination. - Format
Engine - Abstract format engine adhering to the Open-Closed (OCP) and Dependency Inversion (DIP) principles.
- Format
Parser - Abstract parser converting text or byte inputs into a universal
ValueAST.
Functions§
- apply_
merge_ patch - Applies an RFC 7396 JSON Merge Patch in-place to
target. - convert
- Universal cross-format string conversion.
- convert_
bytes - Universal cross-format byte conversion.
- default_
registry - Creates a format registry pre-populated with all enabled built-in format engines.
- diff_
merge_ patch - Computes an RFC 7396 JSON Merge Patch document representing changes from
sourcetotarget. - emit_
csv - Serializes a
Valueto delimited text (CSV / TSV) string. - emit_
ini - Serializes a
Valueto an INI or properties document. - find_
engine - Helper function to find an engine from a static slice by format ID.
- find_
engine_ by_ extension - Helper function to find an engine from a static slice by file extension.
- find_
engine_ by_ mime - Helper function to find an engine from a static slice by MIME type.
- format_
unified_ diff - Formats a human-readable unified diff between two
Valuetrees. - from_
file_ bytes - Parse input byte slice based on file path extension.
- from_
file_ str - Parse input string based on file path extension.
- from_
slice - Universal parse from byte slice into
Valueusing the specified format. - from_
str - Universal parse from string into
Valueusing the specified format. - from_
value - Deserializes a
Valueinto an instance of typeT. - from_
value_ owned - Deserializes an owned
Valueinto an instance of typeT, consuming strings, bytes, arrays, and maps without unnecessary cloning. - infer_
schema - Infers a Draft 2020-12 JSON Schema
Valuefrom a sampleValuedocument. - jsonpath_
query - Convenience function to compile and evaluate a JSONPath expression on a
Valuein one step. - jsonpath_
query_ located - Convenience function to compile and evaluate a JSONPath expression returning located nodes.
- jsonpath_
query_ mut - Convenience function to compile and evaluate a mutable JSONPath expression on a
Valuein one step. - parse_
csv - Parses a CSV or TSV string into a universal
Value. - parse_
ini - Parses an INI or properties document into a universal
Value::Object. - serialize_
to_ visitor - Serializes a Rust value directly into a
FormatVisitorwithout constructing an intermediateValueAST. - sniff_
delimiter - Automatically detects the most probable delimiter in a delimited text sample.
- split_
frontmatter - Splits a document into frontmatter metadata and main body content.
- to_
string - Universal serialize
Valueinto compact UTF-8 string using the specified format. - to_
string_ pretty - Universal serialize
Valueinto pretty-printed UTF-8 string with default indentation. - to_
value - Converts a Rust data structure serializable by Serde into a
Value. - to_vec
- Universal serialize
Valueinto byte vector using the specified format. - transform
- Evaluates a transformation pipeline expression (
stage1 | stage2 | ...) againstinput. - validate_
schema - Convenience function to validate a
Valueagainst a schemaValue.