Skip to main content

babbel_core/
lib.rs

1//! # Babbel Core
2//!
3//! Foundational abstractions, streaming I/O, encoding detection, zero-allocation numeric formatting,
4//! error diagnostic reporting, and universal data model for the Babbel data format family.
5//!
6//! Designed for high performance, standard library, and `no_std` / embedded targets.
7//!
8//! ## Core Modules
9//!
10//! - **[`model::Value`]**: Universal AST supporting null, boolean, integer (i64/u64), float, string, bytes, array, and ordered map.
11//! - **[`query`]**: RFC 9535 JSONPath query engine supporting root references, child property access, array indexing, slicing, filters, and recursive descent.
12//! - **[`patch`]**: RFC 6902 JSON Patch (`add`, `remove`, `replace`, `move`, `copy`, `test`) and RFC 7396 JSON Merge Patch.
13//! - **[`diff`]**: Structural AST diffing producing RFC 6902 and RFC 7396 patches.
14//! - **[`schema`]**: JSON Schema validation (Draft 7 & 2020-12 core assertions, type checks, string formats, array & object constraints).
15//! - **[`codec`]**: Format codecs, pull-parsers, and streaming emitters with format registry dispatch.
16//! - **[`serde_impl`]**: Bidirectional serde interoperability via `to_value` and `from_value` (when `serde` feature enabled).
17
18#![cfg_attr(not(feature = "std"), no_std)]
19#![allow(clippy::approx_constant)]
20
21extern crate alloc;
22
23pub mod chars;
24pub mod codec;
25pub mod compression;
26pub mod csv;
27pub mod diff;
28pub mod embedded;
29pub mod emitters;
30pub mod encoding;
31pub mod error;
32pub mod escape;
33#[cfg(feature = "file-io")]
34pub mod file;
35pub mod ini;
36pub mod io;
37pub mod model;
38pub mod num;
39pub mod patch;
40pub mod query;
41pub mod schema;
42#[cfg(feature = "serde")]
43pub mod serde_impl;
44#[cfg(feature = "std")]
45pub mod testing;
46pub mod text;
47
48// Re-export key primitives for ergonomic downstream usage
49pub use chars::{is_digit, is_hex_digit, is_newline, is_whitespace};
50#[cfg(feature = "alloc")]
51pub use codec::FormatRegistry;
52pub use codec::{
53    BencodeEmitter, CsvEngine, DuplicateKeyMode, FormatCodec, FormatEmitter, FormatEngine,
54    FormatOptions, FormatOptionsBuilder, FormatParser, IniEngine, JsonEmitter, ParseOptions,
55    TomlEmitter, TsvEngine, XmlEmitter, YamlEmitter, find_engine, find_engine_by_extension,
56    find_engine_by_mime,
57};
58pub use compression::{
59    crc32_ieee, lz4_compress, lz4_decompress, snappy_compress, snappy_decompress,
60};
61pub use csv::{
62    CsvFieldsIter, CsvOptions, CsvPullParser, CsvRecord, emit_csv, emit_csv_to, parse_csv,
63    sniff_delimiter,
64};
65pub use diff::{diff, diff_merge_patch, format_unified_diff};
66pub use embedded::{CompactError, EmbeddedLimits, MemoryTracker, StackBuffer};
67pub use encoding::{Encoding, detect_encoding_and_strip_bom, normalize_newlines};
68pub use error::{BabbelError, ErrorCode, Location, Span, format_error_snippet};
69pub use escape::{
70    escape_for_json, escape_for_toml, escape_for_xml, escape_for_yaml, is_valid_toml_bare_key,
71    json_needs_escaping, write_json_escaped_string, write_toml_escaped_string,
72    write_xml_escaped_string, write_yaml_escaped_string, yaml_needs_quoting,
73};
74#[cfg(feature = "file-io")]
75pub use file::{
76    Format, detect_format, list_files_by_extension, read_file_to_string, write_file_from_string,
77};
78pub use ini::{IniEvent, IniOptions, IniPullParser, emit_ini, emit_ini_to, parse_ini};
79pub use io::{
80    ArrayVecDestination, Buffer, BufferDestination, BufferSource, ByteSliceSource,
81    ByteSourceAdapter, IByteReader, IByteStream, ICharStream, IClearable, IDestination,
82    IIndentationAware, ILineReader, ILocationAware, IPeekable, IPositionAware, IRewindable,
83    ISource, ITracked, LineIter, SliceDestination, SliceSource, StringDestination, StringSource,
84};
85#[cfg(feature = "file-io")]
86pub use io::{FileDestination, FileSource};
87pub use model::{ArrayBuilder, FormatVisitor, ObjectBuilder, Value};
88pub use num::{Numeric, format_float, format_integer};
89pub use patch::{Patch, PatchOp, apply_merge_patch};
90pub use query::{
91    JsonPath, LocatedNode, query as jsonpath_query, query_located as jsonpath_query_located,
92    query_mut as jsonpath_query_mut, transform,
93};
94pub use schema::{
95    CompiledSchema, Regex, SchemaValidationError, infer_schema, regex_is_full_match,
96    regex_is_match, validate as validate_schema,
97};
98#[cfg(feature = "serde")]
99pub use serde_impl::{
100    FormatVisitorSerializer, SerdeError, from_value, from_value_owned, serialize_to_visitor,
101    to_value,
102};
103pub use text::{
104    DocumentWithFrontmatter, FrontmatterFormat, decode_hex, dedent, encode_hex, encode_hex_upper,
105    indent, line_count, split_frontmatter, trim_lines,
106};