Expand description
§serde_versioned
A library for handling versioned serialization and deserialization of Rust structs. This crate provides traits and derive macros to support multiple versions of data structures while maintaining backward compatibility.
§Usage
use serde_versioned::{Versioned, FromVersion};
use serde::{Serialize, Deserialize};
#[derive(Versioned, Serialize, Deserialize, Clone)]
#[versioned(versions = [UserV1, UserV2])]
struct User {
pub name: String,
pub age: u32,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct UserV1 {
pub name: String,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct UserV2 {
pub name: String,
pub age: u32,
}
impl FromVersion<User> for UserV1 {
fn convert(self) -> User {
User { name: self.name, age: 0 }
}
}
impl FromVersion<User> for UserV2 {
fn convert(self) -> User {
User { name: self.name, age: self.age }
}
}Structs§
- Version
Conversion Error - Error type for version conversion operations.
Enums§
- Format
Error - Error type for format conversion operations.
Traits§
- From
Version - Trait for converting from a versioned struct to the current struct.
- Versioned
- Trait for handling versioned serialization and deserialization.
Derive Macros§
- Versioned
- Derives the
Versionedtrait for a struct.