Crate to parse and emit EDN
* This lib does not make effort to conform the EDN received to EDN Spec. The lib that generated this EDN should be responsible for this.
* Current example usage in crate https://crates.io/crates/transistor
Cargo.toml
toml
[dependencies]
edn-rs = "0.6.2"
Parse an EDN into a Edn
with edn!
macro:
```rust
extern crate edn_rs;
fn main() { let edn = edn!((sym 1.2 3 false :f nil 3/4)); let expected = Edn::List( List::new( vec![ Edn::Symbol("sym".tostring()), Edn::Double(1.2.into()), Edn::Int(3), Edn::Bool(false), Edn::Key("f".tostring()), Edn::Nil, Edn::Rational("3/4".to_string()) ] ) );
assert_eq!(edn, expected);
} ```
To navigate through Edn
data you can just use get
and get_mut
:
```rust let edn = edn!([ 1 1.2 3 {false :f nil 3/4}]);
asserteq!(edn[1], edn!(1.2)); asserteq!(edn[1], Edn::Double(1.2f64.into())); asserteq!(edn[3]["false"], edn!(:f)); asserteq!(edn[3]["false"], Edn::Key("f".to_string())); ```
Serializes Rust Types into EDN ```rust #![recursionlimit="512"] #[macrouse] extern crate edn_rs;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use crate::edn_rs::serialize::Serialize;
fn main() {
serstruct!{
#[derive(Debug, Clone)]
struct Edn {
btreemap: BTreeMap
println!("{}",edn.serialize());
// { :btreemap {:this-is-a-key [\"with\", \"many\", \"keys\"]}, :btreeset #{3, 4, 5}, :hashmap {:this-is-a-key [\"with\", \"many\", \"keys\"]}, :hashset #{3}, :tuples (3, true, \\d), }
} ```
Emits EDN format from a Json file ```rust use ednrs::jsonto_edn;
fn main() { let json = String::from("{\"hello\": \"world\"}"); let edn = String::from("{:hello \"world\"}");
assert_eq!(edn, json_to_edn(json));
} ```
struct
to map EDN info EdnNode
EdnType
""
"\"string\""
"324352"
, "3442.234"
, "3/4"
:a
sym-bol-s
"[1 :2 \"d\"]"
"(1 :2 \"d\")"
"#{1 2 3}"
"{:a 1 :b 2 }"
"[1 2 [:3 \"4\"]]"
"[1 2 #{:3 \"4\"}]"
"(1 2 (:3 \"4\"))"
"'#{1 2 (:3 \"4\")}"
"{:a 2 :b {:3 \"4\"}}"
, "{:a 2 :b [:3 \"4\"]}"
edn-derive
derive Serialize
derive Deserialize