| Crates.io | rson-core |
| lib.rs | rson-core |
| version | 1.0.0 |
| created_at | 2025-05-31 21:12:26.958869+00 |
| updated_at | 2025-05-31 21:23:42.513273+00 |
| description | Core parsing and value types for RSON |
| homepage | https://rson.dev |
| repository | https://github.com/RSON-Rust-Serialized-Object-Notation/RSON-core |
| max_upload_size | |
| id | 1696642 |
| size | 61,064 |
Core parsing and value types for RSON (Rust Serialized Object Notation)
rson-core is the foundational library for RSON (Rust Serialized Object Notation) - a human-readable data format that extends JSON with rich types, comments, and better developer experience.
This crate provides:
[dependencies]
rson-core = "1.0.0"
use rson_core::{RsonValue, parse_rson_value};
// Parse RSON text into value types
let rson_text = r#"
User(
id: 123,
name: "John Doe",
email: Some("john@example.com"),
roles: ["admin", "user"],
)
"#;
let value: RsonValue = parse_rson_value(rson_text)?;
// Work with the parsed value
match value {
RsonValue::Struct(name, fields) => {
println!("Struct: {}", name);
for (key, val) in fields {
println!(" {}: {:?}", key, val);
}
}
_ => {}
}
pub enum RsonValue {
Null,
Bool(bool),
Number(f64),
String(String),
Array(Vec<RsonValue>),
Object(IndexMap<String, RsonValue>),
Struct(String, IndexMap<String, RsonValue>),
Enum(String, Option<Box<RsonValue>>),
Option(Option<Box<RsonValue>>),
Tuple(Vec<RsonValue>),
}
use rson_core::{parse_rson_value, parse_rson_tokens};
// Parse complete RSON value
let value = parse_rson_value(text)?;
// Tokenize RSON text
let tokens = parse_rson_tokens(text)?;
use rson_core::validate_rson;
// Quick validation without full parsing
let is_valid = validate_rson(rson_text);
User(
id: 123,
name: "John",
active: true,
)
Status::Active
Result::Ok("success")
Color::RGB(255, 128, 0)
Some("value")
None
// Line comment
Config(
/* Block comment */
name: "app",
debug: true, // Trailing comma OK
)
use rson_core::{RsonParser, ParserConfig};
let config = ParserConfig {
allow_comments: true,
allow_trailing_commas: true,
strict_mode: false,
};
let parser = RsonParser::with_config(config);
let value = parser.parse(rson_text)?;
use rson_core::RsonValue;
let mut value = RsonValue::Object(Default::default());
// Add fields to object
if let RsonValue::Object(ref mut map) = value {
map.insert("name".to_string(), RsonValue::String("test".to_string()));
map.insert("version".to_string(), RsonValue::Number(1.0));
}
use rson_core::to_rson_string;
let value = RsonValue::Struct(
"Config".to_string(),
[("name".to_string(), RsonValue::String("app".to_string()))]
.into_iter().collect()
);
let rson_text = to_rson_string(&value)?;
println!("{}", rson_text);
// Output: Config(name: "app")
// For high-level Serde integration, use serde_rson
use serde_rson;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct MyStruct {
field: String,
}
// For schema validation
use rson_schema::validate_against_schema;
Use rson-core when:
Use serde_rson when:
We welcome contributions! Please see our Contributing Guide.
Areas we need help with:
This project is licensed under the MIT License - see the LICENSE file for details.
Made with 🦀 by the RSON community