6

What am I doing wrong? Is that not how we use tuples in rust?

Account:

#[account]
pub struct UserLedger {
    pub list: Vec<(String, u32)>,
}

Error Message:

Error: Type not found: {"type":{"defined":"(String,u32)"}}

1

1 Answer 1

4

tuples are not implemented in anchor so far (version: 0.27.0 at time of writing), you can use a struct in your case.

#[account]
pub struct UserLedger {
    pub list: Vec<MyTuple>,
}

#[derive(AnchorSerialize, AnchorDeserialize)]
struct MyTuple {
    my_string: String,
    my_u32: u32
}

for an enum as well you are not allowed to use tuples, which is quite common, but you can use it like this:

#[derive(AnchorSerialize, AnchorDeserialize)]
pub enum Grade {
    Pass { value: u64 },
    Fail { value: u64, next_attempt: MyDate },
}
2
  • 1
    In your fix, pub list: Vec<(String, u32)> should be pub list: Vec<MyTuple>? ` Commented Apr 21, 2023 at 14:36
  • 1
    thanks @Nawaz fixed.
    – lucarlig
    Commented Apr 22, 2023 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.