rson-core 1.0.0

Core parsing and value types for RSON
Documentation
//! # RSON Core
//!
//! Core parsing and value types for RSON (Rust Serialized Object Notation).
//! 
//! RSON is a human-readable data serialization format designed as a superset of JSON,
//! with support for richer data structures like enums, structs, tuples, and optionals.
//!
//! ## Features
//!
//! - **JSON Compatibility**: Any valid JSON is valid RSON
//! - **Rich Types**: Structs, enums, tuples, optionals beyond JSON's types
//! - **Developer-Friendly**: Comments, trailing commas, unquoted identifiers
//! - **Efficient**: Zero-copy parsing where possible
//!
//! ## Example
//!
//! ```rson
//! // Example RSON document
//! User(
//!     id: 1,
//!     name: "Dedan",
//!     email: Some("dedan@example.com"),
//!     roles: ["admin", "editor"],
//!     settings: {
//!         theme: "dark",
//!         notifications: true,
//!     },
//! )
//! ```

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "alloc")]
extern crate alloc;

pub mod value;
pub mod parser;
pub mod error;
pub mod formatter;

pub use value::{RsonValue, RsonType};
pub use parser::{parse_rson, parse_rson_value};
pub use error::{RsonError, RsonResult};
pub use formatter::{format_rson, format_pretty, format_compact, Formatter, FormatOptions};

/// Parse an RSON string into a `RsonValue`.
///
/// This is the main entry point for parsing RSON text.
///
/// # Examples
///
/// ```
/// use rson_core::parse;
///
/// let input = r#"User(name: "Alice", age: 30)"#;
/// let value = parse(input).unwrap();
/// ```
pub fn parse(input: &str) -> RsonResult<RsonValue> {
    parse_rson(input)
}

/// Format a `RsonValue` as an RSON string.
///
/// # Examples
///
/// ```
/// use rson_core::{RsonValue, format};
///
/// let value = RsonValue::String("Hello, RSON!".to_string());
/// let formatted = format(&value).unwrap();
/// assert_eq!(formatted, r#""Hello, RSON!""#);
/// ```
pub fn format(value: &RsonValue) -> RsonResult<String> {
    format_rson(value, &FormatOptions::default())
}