Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archive schema update? #486

Open
XavDesbordes opened this issue Mar 28, 2024 · 0 comments
Open

Archive schema update? #486

XavDesbordes opened this issue Mar 28, 2024 · 0 comments

Comments

@XavDesbordes
Copy link

XavDesbordes commented Mar 28, 2024

Hi,
Say at time T0, Ihave the following struct:

#[derive(Archive, Serialize, Deserialize)]
struct A {
        a: u32,
        b: String,
}

Later, and at T1, I decide to add a field:

#[derive(Archive, Serialize, Deserialize)]
struct A {
        a: u32,
        b: String,
        c: u32
}

Doing like so, I get "attempt to subtract with overflow", which is kind of expected.
Currently, the only way I found is to add the struct version in the name and have a conversion function:

#[derive(Archive, Serialize, Deserialize)]
struct A0 {
        a: u32,
        b: String,
}

#[derive(Archive, Serialize, Deserialize)]
struct A1 {
        a: u32,
        b: String,
        c : u32
}

fn convert_a0_to_a1(...)->A1{
      //deserialize A0, reserialize to A1 here
}

Is there a way (attribute or anything) to avoid this ?

Is an attribute possible, like:

#[derive(Archive, Serialize, Deserialize)]
struct A {
        a: u32,
        b: String,
        #[optional]
        c : u32
}

that would not cause a hard error if the field is not present in the calculation (but I guess that would really make the code more difficult).

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant