Skip to main content

Crate babbel

Crate babbel 

Source
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), universal Value AST, 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 .env parsing/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 + alloc compression 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 ergonomic Value construction.
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 / yq style operators over Value).

Macros§

value
Constructs a babbel_core::Value using literal syntax.

Structs§

ArrayBuilder
Fluent builder for constructing Value::Array.
ArrayVecDestination
Stack-allocated fixed-capacity byte buffer destination using const generics.
AvroEngine
Format engine for Apache Avro binary payloads (.avro).
BabbelError
Unified, structured error type for polyglot serialization and parsing.
BencodeEngine
Bencode format engine implementing FormatEngine.
BsonEngine
BSON format engine implementing FormatEngine.
CborEngine
CBOR format engine implementing FormatEngine.
CompactError
Zero-allocation 8-byte diagnostic error for bare-metal embedded targets (no_alloc).
CompiledSchema
A compiled, optimized JSON Schema validator ready for zero-allocation reuse.
CsvEngine
Standard built-in CSV format engine implementing FormatEngine.
CsvFieldsIter
Zero-allocation iterator over fields within a CsvRecord.
CsvOptions
Configuration options for delimited text (CSV / TSV) parsing and serialization.
CsvPullParser
Zero-allocation streaming CSV pull parser for microcontrollers and embedded systems.
CsvRecord
A borrowed CSV record (row) referencing slices in the original input buffer.
DocumentWithFrontmatter
Represents a parsed document containing optional frontmatter metadata and body content.
EmbeddedLimits
Runtime and compile-time limits to protect against stack overflows and excessive resource consumption.
FormatOptions
Universal format serialization options.
FormatOptionsBuilder
Fluent builder for FormatOptions.
FormatRegistry
Dynamic format engine registry supporting lookup by format ID, MIME type, or file extension.
FormatVisitorSerializer
Serializer that drives a FormatVisitor directly 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.
IniPullParser
Zero-allocation streaming INI and property file pull parser.
Json5Engine
JSON5 and JSONC format engine implementing FormatEngine.
JsonEngine
JSON format engine implementing FormatEngine.
JsonLinesEngine
JSON Lines format engine implementing FormatEngine.
JsonPath
A compiled RFC 9535 JSONPath expression.
KdlEngine
KDL format engine implementing FormatEngine.
LocatedNode
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.
MemoryTracker
Tracks memory allocations and peak watermarks for resource-constrained environments.
MsgPackEngine
MessagePack format engine implementing FormatEngine.
ObjectBuilder
Fluent builder for constructing Value::Object.
ParquetEngine
Apache Parquet format engine implementing FormatEngine.
ParseOptions
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.
SchemaValidationError
Structured validation error containing pointer location, failed keyword, and error description.
SerdeError
Error type for Serde conversions with Value.
SliceDestination
Zero-allocation in-memory destination writing directly into a caller-supplied byte slice.
Span
Source code span identifying start and end locations.
StackBuffer
Fixed-size stack-allocated byte buffer using const generics.
TomlEngine
TOML format engine implementing FormatEngine.
TsvEngine
Standard built-in TSV format engine implementing FormatEngine.
XmlEngine
XML format engine implementing FormatEngine.
YamlEngine
YAML format engine implementing FormatEngine.

Enums§

DuplicateKeyMode
Strategy for handling duplicate keys during object / mapping parsing.
ErrorCode
Standardized diagnostic error codes across format parsers, encoders, and validators.
FrontmatterFormat
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§

FormatCodec
A combined format codec providing both parsing and emission capabilities.
FormatEmitter
Abstract emitter writing a universal Value AST to an output destination.
FormatEngine
Abstract format engine adhering to the Open-Closed (OCP) and Dependency Inversion (DIP) principles.
FormatParser
Abstract parser converting text or byte inputs into a universal Value AST.

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 source to target.
emit_csv
Serializes a Value to delimited text (CSV / TSV) string.
emit_ini
Serializes a Value to 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 Value trees.
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 Value using the specified format.
from_str
Universal parse from string into Value using the specified format.
from_value
Deserializes a Value into an instance of type T.
from_value_owned
Deserializes an owned Value into an instance of type T, consuming strings, bytes, arrays, and maps without unnecessary cloning.
infer_schema
Infers a Draft 2020-12 JSON Schema Value from a sample Value document.
jsonpath_query
Convenience function to compile and evaluate a JSONPath expression on a Value in 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 Value in 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 FormatVisitor without constructing an intermediate Value AST.
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 Value into compact UTF-8 string using the specified format.
to_string_pretty
Universal serialize Value into 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 Value into byte vector using the specified format.
transform
Evaluates a transformation pipeline expression (stage1 | stage2 | ...) against input.
validate_schema
Convenience function to validate a Value against a schema Value.