use borsh::{to_vec, BorshSerialize};
use borsh_incremental::BorshDeserializeIncremental;
#[derive(BorshSerialize, BorshDeserializeIncremental, Debug, PartialEq)]
struct ExampleV1 {
#[incremental(default = "Unnamed".to_string())]
name: String,
count: u32,
}
#[derive(BorshDeserializeIncremental, Debug, PartialEq)]
struct ExampleV2 {
#[incremental(default = "Unnamed".to_string())]
name: String,
count: u32,
#[incremental(default = "active".to_string())]
status: String, }
fn main() {
let old = ExampleV1 {
name: "Alice".into(),
count: 5,
};
let old_bytes = to_vec(&old).unwrap();
let parsed_v2 = ExampleV2::try_from(&old_bytes[..]).unwrap();
println!("Backward-compatible decode: {:?}", parsed_v2);
let truncated = &old_bytes[..4];
let partial = ExampleV2::try_from(truncated).unwrap();
println!("Partial decode with defaults: {:?}", partial);
}