A simple library to convert structs to JSON.
```rs
use jsonify::Serializable;
struct Foo { bar: String, baz: i32 }
impl Serializable for Foo { fn serialize(&self) -> String { json!( bar => self.bar, baz => self.baz ) } }
fn main() { let foo = Foo { bar: "Hello!".to_string(), baz: 30 };
println!("{}", foo.serialize()); // Output: {"bar": "Hello!", "baz": 30}
} ```
Import JSONify and Serializable trait
```rs
use jsonify::Serializable; ```
Create struct Foo
rs
struct Foo {
bar: String,
baz: i32
}
Implement Serializable
trait
rs
impl Serializable for Foo {
fn serialize(&self) -> String {
// ...
}
}
Calls json! macro to create JSON string
rs
/*
Usage:
json!(
key => value,
key2 => value2
)
*/
json!(
bar => self.bar,
baz => self.baz
)
Create instance of Foo
and serialize it
```rs fn main() { let foo = Foo { bar: "Hello!".to_string(), baz: 30 };
println!("{}", foo.serialize()); // Output: {"bar": "Hello!", "baz": 30}
} ```