Expand description
§Cirru EDN
Extensible Data Notation (EDN) implementation using Cirru syntax.
This crate provides a data format similar to EDN but using Cirru’s syntax instead of traditional s-expressions. It supports rich data types including primitives, collections, and special constructs like records and tuples.
§Features
- Rich data types: nil, boolean, number, string, symbol, tag, list, set, map, record, tuple, buffer, atom
- Serde integration: Seamless serialization/deserialization with Rust structs
- Efficient string handling: Uses
Arc<str>for string deduplication - Runtime references: Support for arbitrary Rust data via
AnyRef - Type-safe API: Strong typing with convenient conversion methods
§Basic Usage
use cirru_edn::{parse, format, Edn};
// Parse Cirru EDN from string
let data = parse("[] 1 2 3").unwrap();
// Create EDN values programmatically
let map = Edn::map_from_iter([
(Edn::tag("name"), Edn::str("Alice")),
(Edn::tag("age"), Edn::Number(30.0)),
]);
// Format back to string
let formatted = format(&map, true).unwrap();§Type Checking and Conversion
The library provides type-safe methods for checking and converting values:
use cirru_edn::Edn;
let value = Edn::Number(42.0);
// Type checking
assert!(value.is_number());
assert!(!value.is_string());
// Safe conversion
let number: f64 = value.read_number().unwrap();
assert_eq!(number, 42.0);
// Get type name for debugging
assert_eq!(value.type_name(), "number");§Working with Collections
use cirru_edn::Edn;
// Create and access lists
let list = Edn::List(vec![
Edn::Number(1.0),
Edn::str("hello"),
Edn::Bool(true)
].into());
if let Some(first) = list.get_list_item(0) {
assert_eq!(first.read_number().unwrap(), 1.0);
}
// Create and access maps
let map = Edn::map_from_iter([
(Edn::tag("name"), Edn::str("Bob")),
(Edn::tag("age"), Edn::Number(25.0)),
]);
if let Some(name) = map.get_map_value(&Edn::tag("name")) {
assert_eq!(name.read_string().unwrap(), "Bob");
}§Serde Integration
The crate includes built-in serde support for seamless serialization:
use cirru_edn::{to_edn, from_edn};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Person {
name: String,
age: u32,
}
let person = Person { name: "Bob".to_string(), age: 25 };
let edn_value = to_edn(&person).unwrap();
let recovered: Person = from_edn(edn_value).unwrap();Re-exports§
Modules§
- serde_
support - Serde support for Edn data format.
Structs§
- EdnAny
Ref - data inside any-ref is allowed to be mutable
- EdnList
View - List interface for Edn::List
- EdnMap
View - Map interface for Edn::Map
- EdnRecord
View - Record interface for Edn::Record
- EdnSet
View - EdnTag
- Tags across whole program with strings reused for efficiency.
- EdnTuple
View - Position
- Position information in the source text.
Enums§
- Edn
- Extensible Data Notation (EDN) value representation.
- EdnError
- Errors that can occur during EDN parsing and manipulation.
Traits§
- DynEq
- https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c39e1eef6c8c10e973fa629103b4a0b1
Functions§
- format
- Generate formatted string from Edn data.
- is_
simple_ char - check if a char is simple enough to be printed without quotes
- parse
- Parse Cirru code into Edn data.