use kowito_json_derive::KJson;
#[derive(Debug, KJson)]
pub struct User {
pub id: u64,
pub name: String,
pub score: f64,
pub is_active: bool,
}
fn main() {
let user = User {
id: 1,
name: "Alice".to_string(),
score: 98.6,
is_active: true,
};
let mut buf = Vec::new();
user.to_json_bytes(&mut buf);
let json = std::str::from_utf8(&buf).unwrap();
println!("Serialized: {json}");
let prefix = b"data=";
let mut out = prefix.to_vec();
user.to_json_bytes(&mut out);
println!("Appended: {}", std::str::from_utf8(&out).unwrap());
}