Skip to content

Commit

Permalink
Add simple serialization example (good starting point for no_std).
Browse files Browse the repository at this point in the history
  • Loading branch information
Grinkers committed Dec 23, 2023
1 parent f39709c commit 169b895
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/simple_serialize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use edn_rs::Serialize;

struct Foo<'a> {
value: u64,
say: &'a str,
}

impl Serialize for Foo<'_> {
fn serialize(&self) -> String {
format!("{{:value {}, :say {:?}}}", self.value, self.say)
}
}

fn serialize() -> String {
let say = "Hello, World!";
let foo = Foo {
value: 42,
say: say,
};

edn_rs::to_string(&foo)
}

fn main() {
println!("{}", serialize());
}

#[test]
fn test_serialize() {
assert_eq!(serialize(), "{:value 42, :say \"Hello, World!\"}");
}

0 comments on commit 169b895

Please sign in to comment.