diff --git a/examples/simple_serialize.rs b/examples/simple_serialize.rs new file mode 100644 index 0000000..b0c7c46 --- /dev/null +++ b/examples/simple_serialize.rs @@ -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!\"}"); +}