Module serde_support

Module serde_support 

Source
Expand description

Serde integration for typed read/write of Rust structs to fabric memory.

Enabled by the serde feature flag. Uses postcard for compact, no_std-friendly serialization. This module extends FabricMem with write_struct and read_struct methods.

§Example

use grafos_std::mem::FabricMem;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Config {
    version: u32,
    name: String,
}

let mem = FabricMem::hello()?;
let config = Config { version: 1, name: "node-1".into() };

let written = mem.write_struct(0, &config)?;
let restored: Config = mem.read_struct(0, written as u32)?;
assert_eq!(restored, config);