Error in BorshSerialize/Deserialize when struct pulled from another crate

Viewed 19

I have a struct A in a.rs that I am trying to serialize with Borsh serialization with Rust. A is shown below.

use crate::B;

#[derive(Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct A {
 pub a: i32
 pub b: Vec<B>,
};

Here B is in some other file where I express B as follows in some file b.rs within same lib.rs.

#[derive(Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct B {
 pub a1: i32
 pub b2: Vec<i32>,
};

When I build the crate I get the following error.

#[derive(Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
                               ^^^^^^^^^^^^^^the trait `BorshSerialize` is not implemented for `b::B`
= help: the following other types implement trait `BorshSerialize`:
             &T
             ()
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0, T1, T2, T3, T4, T5, T6)
           and 110 others
   = note: required because of the requirements on the impl of `BorshSerialize` for `Vec<b::B>`

Its very weird because in b.rs , I am already defining the macro #[derive(Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)] for B. Will I have to move B above A or is there anything else I am missing out.

0 Answers
Related