rson_core/
lib.rs

1//! # RSON Core
2//!
3//! Core parsing and value types for RSON (Rust Serialized Object Notation).
4//! 
5//! RSON is a human-readable data serialization format designed as a superset of JSON,
6//! with support for richer data structures like enums, structs, tuples, and optionals.
7//!
8//! ## Features
9//!
10//! - **JSON Compatibility**: Any valid JSON is valid RSON
11//! - **Rich Types**: Structs, enums, tuples, optionals beyond JSON's types
12//! - **Developer-Friendly**: Comments, trailing commas, unquoted identifiers
13//! - **Efficient**: Zero-copy parsing where possible
14//!
15//! ## Example
16//!
17//! ```rson
18//! // Example RSON document
19//! User(
20//!     id: 1,
21//!     name: "Dedan",
22//!     email: Some("dedan@example.com"),
23//!     roles: ["admin", "editor"],
24//!     settings: {
25//!         theme: "dark",
26//!         notifications: true,
27//!     },
28//! )
29//! ```
30
31#![cfg_attr(not(feature = "std"), no_std)]
32
33#[cfg(feature = "alloc")]
34extern crate alloc;
35
36pub mod value;
37pub mod parser;
38pub mod error;
39pub mod formatter;
40
41pub use value::{RsonValue, RsonType};
42pub use parser::{parse_rson, parse_rson_value};
43pub use error::{RsonError, RsonResult};
44pub use formatter::{format_rson, format_pretty, format_compact, Formatter, FormatOptions};
45
46/// Parse an RSON string into a `RsonValue`.
47///
48/// This is the main entry point for parsing RSON text.
49///
50/// # Examples
51///
52/// ```
53/// use rson_core::parse;
54///
55/// let input = r#"User(name: "Alice", age: 30)"#;
56/// let value = parse(input).unwrap();
57/// ```
58pub fn parse(input: &str) -> RsonResult<RsonValue> {
59    parse_rson(input)
60}
61
62/// Format a `RsonValue` as an RSON string.
63///
64/// # Examples
65///
66/// ```
67/// use rson_core::{RsonValue, format};
68///
69/// let value = RsonValue::String("Hello, RSON!".to_string());
70/// let formatted = format(&value).unwrap();
71/// assert_eq!(formatted, r#""Hello, RSON!""#);
72/// ```
73pub fn format(value: &RsonValue) -> RsonResult<String> {
74    format_rson(value, &FormatOptions::default())
75}