Skip to main content

FromVersion

Trait FromVersion 

Source
pub trait FromVersion<T>: Sized {
    // Required method
    fn convert(self) -> T;
}
Expand description

Trait for converting from a versioned struct to the current struct.

This trait must be implemented for each version struct to define how it converts to the current version of the struct.

§Example

use serde_versioned::FromVersion;

struct User { name: String, age: u32 }
struct UserV1 { name: String }

impl FromVersion<User> for UserV1 {
    fn convert(self) -> User {
        User { name: self.name, age: 0 }
    }
}

Required Methods§

Source

fn convert(self) -> T

Converts a versioned struct instance to the current struct type.

§Arguments
  • self - The versioned struct instance to convert
§Returns

The converted current struct instance

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§