edn-rs
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. For more information on Edn Spec please visit: https://github.com/edn-format/edn.
- Minimal Rust Version is 1.46+.
Our MTTA (Mean time to acknowledge) is around one day
;
and our TTR (Time To Resolve) can vary from a few days to a couple of weeks
depending on the number of issues.
Current example usage in:
Usage
Cargo.toml
[]
= "0.17.0"
Simple time-only benchmarks of edn-rs
against Clojure Edn
- Link to benchmarks implementation here
Method\Lang | Rust --release | Rust --debug | Clojure |
---|---|---|---|
parse string | 77.57µs | 266.479µs | 4.712235 milis |
get-in/navigate (3 blocks) | 4.224µs | 22.861µs | 26.333 µs |
Deserialize to struct | 110.358µs | 357.054µs | 4.712235 milis |
parse with criterium | 11.348µs | - | 23.230µs |
Quick reference
Parse an EDN token into a Edn
with edn!
macro:
use ;
Parse an EDN String with Edn::from_str
:
use ;
use FromStr;
To navigate through Edn
data you can just use get
and get_mut
:
use ;
Serializes Rust Types into EDN with edn-derive::Serialize
use ;
use ;
use Serialize;
Deserializes Strings into Rust Types:
For now you have to implement the conversion yourself with the
Deserialize
trait. Soon you'll be able to have that implemented for you viaedn-derive
crate.
use ;
Deserializes Edn types into Rust Types:
- Deserialization to
std::collection::*
is currently unsafe.
For now you have to implement the conversion yourself with the
Deserialize
trait. Soon you'll be able to have that implemented for you viaedn-derive
crate.
use ;
Emits EDN format from a Json:
- This function requires feature
json
to be activated. To enable this feature add to yourCargo.toml
dependencies the following lineedn-rs = { version = 0.17.0", features = ["json"] }
.
use json_to_edn;
Emits a JSON from type edn_rs::Edn
.
- The associated emthod is
to_json(&self)
and it requires featurejson
to be activated. To enable this feature add to yourCargo.toml
dependencies the following lineedn-rs = { version = 0.17.0", features = ["json"] }
.
use FromStr;
to_string/to_debug
to_debug
emits a Debug version of Edn
type.
use ;
let edn = Vector;
let expected = "Vector(Vector([Int(5), Int(6), Int(7)]))";
assert_eq!;
to_string
emits a valid edn.
use ;
let edn = Vector;
let expected = "[5, 6, 7, ]";
assert_eq!;
Larger to_string
example:
Using async/await
with Edn type
Edn supports futures
by using the feature async
. To enable this feature add to your Cargo.toml
dependencies the following line edn-rs = { version = 0.17.0", features = ["async"] }
and you can use futures as in the following example.
use ;
use *;
use Future;
use *;
async + Send
async
The objective of foo
is to show that Edn
can be wrapped with a Future
. If you want to return an Edn
from an async
function just use:
async
Edn-rs Current Features
- Define
struct
to map EDN infoEdnNode
- Define EDN types,
EdnType
- Edn Type into primitive:
Edn::Bool(true).into() -> true
. This was done byto_float
,to_bool
,to_int
,to_vec
. - implement
futures::Future
trait toEdn
-
to_string()
forEdn
. -
to_debug()
forEdn
.
- Edn Type into primitive:
- Parse EDN data
from_str
:- nil
""
- String
"\"string\""
- Numbers
"324352"
,"3442.234"
,"3/4"
- Keywords
:a
- Symbol
sym-bol-s
with a maximum of 200 chars - Vector
"[1 :2 \"d\"]"
- List
"(1 :2 \"d\")"
- Set
"#{1 2 3}"
- Map
"{:a 1 :b 2 }"
- Inst
#inst \"yyyy-mm-ddTHH:MM:ss\"
- UUID
#uuid \"<some-uuid>\"
- Nested structures
"{:a \"2\" :b [true false] :c #{:A {:a :b} nil}}"
- nil
- Simple data structures in one another
edn!
:- Vec in Vec
"[1 2 [:3 \"4\"]]"
- Set in Vec
"[1 2 #{:3 \"4\"}]"
- List in List
"(1 2 (:3 \"4\"))"
- List in Set
"'#{1 2 (:3 \"4\")}"
- Maps in general
"{:a 2 :b {:3 \"4\"}}"
,"{:a 2 :b [:3 \"4\"]}"
- Namespaced Maps
":abc{0 5 1 "hello"}
, unfortunately now this is misinterpreted as a keyword
- Vec in Vec
- Multiple simple data structures in one another (Map and Set in a vector)
- Multi deepen data structures (Map in a Set in a List in a Vec in a Vec)
- Navigate through Edn Data
- Navigate through Sets. DOne by
set_iter
- Navigate through Sets. DOne by
- Json to Edn
- Json String to EDN String
- macro to process Structs and Enums to EDN
- trait Deserialize EDN to Struct
- trait Serialize struct to EDN
edn-derive
edn-derive
is a proc-macro crate to (De)serialize Edn values, currently it is beta and it can be found at crates.io
or at github
.
Usage
Just add to your Cargo.toml
the following:
[]
= "<version>"
= "0.17.0"
Examples
Serialize
use Serialize;
Deserialization
use Deserialize;
use EdnError;
// The `Debug` and `PartialEq` are only necessary because of `assert_eq`, you don't need them
Current Features
-
derive Serialize
-
edn_rs::to_string
-
derive Deserialize
-
let val: YourStruct = edn_rs::from_str(&str)