babbel_core
Foundational architectural kernel for the Babbel multi-format serialization ecosystem. babbel_core provides unified streaming I/O abstractions adhering strictly to SOLID principles, universal Value AST, RFC 4180 CSV/TSV, sectioned INI/.env, frontmatter processing, Unicode BOM detection, zero-allocation numeric formatting, diagnostic error reporting, and string escaping.
Features
- SOLID Streaming I/O (
babbel_core::io):- Segregated capability traits:
ILineReader,IByteStream,IByteWriter,ICharStream,IRewindable,IPositionAware,ILocationAware,IClearable,ITailInspectable,IFlushable,IIndentationAware,IStatefulStream. - Unified input sources:
BufferSource,FileSource(with 64 MB DoS guard),SliceSource,StringSource,ReaderSource(genericReadstreaming withBufReader). - Unified output destinations:
Buffer,FileDestination,StringDestination,SliceDestination,ArrayVecDestination. - Stream state snapshots:
SaveStateandIStatefulStreamfor transactional backtracking. - Line-by-line reading across mixed CRLF, LF, and CR newlines.
- Zero-allocation line slicing (
SliceSource::read_line_slice()). - Safe in-memory tail tracking (
last()) without file system re-opening. - Full Unicode scalar decoding preventing multi-byte UTF-8 corruption.
- Segregated capability traits:
- Embedded & Zero-Allocation Primitives (
babbel_core::embedded):- Stack allocation:
StackBuffer<const N>,MemoryTracker,EmbeddedLimits,CompactError(8 bytes). - Zero-allocation destinations:
SliceDestination<'a>andArrayVecDestination<const N>.
- Stack allocation:
- Universal Data Model (
babbel_core::model):ValueAST (Null,Bool,Integer(i128),Float,String,Array,Object,Bytes) powering cross-format conversions.
- Tabular Text Engine (
babbel_core::csv):- RFC 4180 CSV and TSV parsing and serialization.
- Delimiter auto-detection (
sniff_delimiter) across,,\t,;,|. - Multi-line quoted fields, double-quote escaping (
""), and automatic scalar type inference.
- Configuration Text Engine (
babbel_core::ini):- Sectioned INI (
[section]), Java.properties, and.envparsing and serialization. - Comments (
#,;,!), delimiters (=,:), and global root keys.
- Sectioned INI (
- Document Frontmatter & Text Utilities (
babbel_core::text):- Frontmatter splitter (
split_frontmatter) supporting YAML (---) and TOML (+++). - Indentation manipulation:
indent,dedent,trim_lines,line_count.
- Frontmatter splitter (
- Unified Codec Interfaces (
babbel_core::codec):FormatParser,FormatEmitter, andFormatCodecabstractions.
- Unicode & Text Engine (
babbel_core::encoding&babbel_core::escape):- Automatic BOM detection for UTF-8, UTF-16 LE/BE, and UTF-32 LE/BE.
- Cross-platform newline normalization (
\r\n/\r$\rightarrow$\n). - Standardized escaping for JSON, XML, and YAML.
- Zero-Allocation Numeric Formatting (
babbel_core::num):- Fast integer formatting via
itoaand float formatting viadtoa.
- Fast integer formatting via
- Diagnostic Error Reporting (
babbel_core::error):- Structured
BabbelError,ErrorCode,Span, and formatted context snippets.
- Structured
no_stdSupport:- Compiles cleanly in embedded and bare-metal environments with the
allocfeature.
- Compiles cleanly in embedded and bare-metal environments with the
Installation
Add to your Cargo.toml:
[]
= "0.1.1"
Or as a workspace path dependency:
[]
= { = "crates/babbel_core" }
Feature Flags
| Feature | Default | Description |
|---|---|---|
std |
Yes | Enables standard library support and OS integration. |
alloc |
Yes (via std) |
Enables heap allocation primitives (String, Vec) for no_std. |
file-io |
Yes | Enables FileSource, FileDestination, and disk file utilities. |
Quickstart & Code Examples
1. Line-by-Line Text Streaming (ILineReader)
use ;
let text = "alpha\r\nbeta\ngamma\rdelta";
let mut source = new;
while let Some = source.read_line
// Zero-copy borrowed slice iteration
let mut source2 = new;
while let Some = source2.read_line_slice
2. Delimited Text (CSV / TSV)
use ;
// 1. Sniff delimiter
let data = "col1\tcol2\nval1\tval2\n";
assert_eq!;
// 2. Parse TSV
let val = parse_csv.unwrap;
// 3. Emit CSV
let csv_out = emit_csv.unwrap;
println!;
3. Configuration Text (INI / .env)
use ;
// Parse INI with sections
let ini_text = "[server]\nhost = 127.0.0.1\nport = 8080\n";
let val = parse_ini.unwrap;
// Parse .env
let env_text = "PORT=3000\nDATABASE_URL=sqlite://data.db\n";
let env_val = parse_ini.unwrap;
4. Document Frontmatter & Text Utilities
use ;
// Split Markdown frontmatter
let doc = "---\ntitle: Guide\n---\n# Welcome";
let res = split_frontmatter;
assert_eq!;
assert_eq!;
// Dedent code block
let indented = " fn run() {\n 42\n }";
assert_eq!;
Universal Value Model
The Value enum enables lossless structural representation across format boundaries:
use Value;
let node = Object;
assert!;
Documentation
See the Documentation Hub for full workspace guides:
- Architecture Guide
- Embedded Systems Guide
- Text Support Guide
- Security Policy
- Development Guide
- Contributing Guidelines
License
Licensed under the MIT License.