| Crates.io | serde_yad |
| lib.rs | serde_yad |
| version | 1.0.1 |
| created_at | 2025-09-17 04:11:33.997431+00 |
| updated_at | 2025-09-17 04:25:28.101842+00 |
| description | Serde_YAD serializes and deserializes YAD files. |
| homepage | |
| repository | https://github.com/KingsBeCattz/yad |
| max_upload_size | |
| id | 1842745 |
| size | 60,494 |
serde_yad is a Rust crate for binary serialization and deserialization of YAD Core structures.
It takes the primitive Value types from yad_core (all supported types and their representations) and implements them in a binary format inspired by JSON/BSON.
With serde_yad, you can serialize and deserialize entire YAD files, individual rows, keys, or single values.
Value, Key, and Row.Add this to your Cargo.toml:
[dependencies]
serde_yad = "1.0.0"
yad_core = "2.0.0"
Value or Keyuse serde_yad::{encode_value, encode_key, decode_value, decode_key};
use yad_core::{Value, Key};
fn main () {
let key = Key {
name: "score".to_string(),
value: Value::from(100),
};
// Encode key to binary
let bytes = encode_key(&key).unwrap();
// Decode back to Key
let decoded_key = decode_key(&bytes).unwrap();
assert_eq!(decoded_key.name, key.name);
assert_eq!(decoded_key.value, key.value);
}
Row with multiple Keysuse serde_yad::{encode_row, decode_row};
use yad_core::{Row, Key, Value};
fn main() {
let row = Row {
name: "player1".to_string(),
keys: vec![
Key { name: "score".into(), value: Value::from(100) },
Key { name: "level".into(), value: Value::from(5) },
],
};
// Encode row
let bytes = encode_row(&row).unwrap();
// Decode row
let decoded_row = decode_row(&bytes).unwrap();
assert_eq!(decoded_row.name, row.name);
assert_eq!(decoded_row.keys.len(), row.keys.len());
}
This example demonstrates creating a YAD file, writing it to disk, and reading it back.
use yad_core::Value;
use serde_yad::key::Key;
use serde_yad::{Version, YAD};
fn write_a_new_yad() {
let mut yad = YAD::new_empty(Version {
major: 1,
minor: 0,
patch: 0,
beta: 0,
});
yad.insert_row("johan", vec![
Key::new("name", Value::try_from("Johan").unwrap())
]);
let yad_path = "./examples/my_first_yad.yad";
std::fs::write(yad_path, yad.serialize().unwrap()).unwrap();
}
fn read_a_yad() {
let yad_path = "./examples/example.yad";
let yad = YAD::deserialize(std::fs::read(yad_path).unwrap()).unwrap();
println!("{}", yad);
}
fn main() {
write_a_new_yad();
read_a_yad();
}
This example demonstrates:
Version.Key containing a Value.ROW_START_HEADER (0xF1) – marks the beginning of a row.ROW_NAME_HEADER (0x60) – row name follows.ROW_END_HEADER (0xF2) – marks the end of a row.KEY_START_HEADER (0xF3) – marks the beginning of a key.KEY_NAME_HEADER (0x70) – key name follows.KEY_END_HEADER (0xF4) – marks the end of a key.Each Value type has its own byte representation for efficient storage.
MIT License. See LICENSE for details.