0

I'm trying to save AccountInfo in a struct that #[derive(BorshSerialize, BorshDeserialize, Clone, Debug)] to send SOL to this account. AccountInfo is a struct in library that don't impl serialize method. This account is randomly chosen from a map in contract so I cannot pass it into data to make instructions. This is the code:

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug)]
pub struct State<'a> {
    pub owner: AccountInfo<'a>,
}
marethyu
  • 95
  • 6
  • From the [source of the serialize macro](https://docs.rs/borsh-derive-internal/0.9.3/src/borsh_derive_internal/struct_ser.rs.html#28) you can see to derive `BorshSerialize` all fields that are not `borsh_skip`ped have to implement `BorshSerialize`, and that's a common requrement for derives. You'll have to implement `BorshSerialize` and `BorshDeserialize` by hand. – cafce25 Jan 13 '23 at 12:00
  • Thanks for your reply @cafce25! But when I try to impl BorshSerialize for AccountInfo, the compiler said "only traits defined in the current crate can be implemented for types defined outside of the crate" and AccountInfo is a type that is defined in another library, which is outside of the crate. So this is a dead end or am I wrong? – marethyu Jan 16 '23 at 02:29
  • You misunderstood, you'll have to implement them for `State` – cafce25 Jan 16 '23 at 08:37

0 Answers0