0

Before anchor 0.29.0, BTreeMaps where working correctly in my programs, but now that I'm moving to ^0.29.0 I'm getting the following errors for every BTreeMap when I'm building my program.

no associated item named `__anchor_private_insert_idl_defined` found for struct `std::collections::BTreeMap` in the current scope

no associated item named `__anchor_private_gen_idl_type` found for struct `std::collections::BTreeMap` in the current scope

no associated item named `__anchor_private_full_path` found for struct `std::collections::BTreeMap` in the current scope

#[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Debug, Clone)]
      |          ^^^^^^^^^^^^^^^ associated item not found in `BTreeMap<u64, u8>`

note: this error originates in the derive macro `AnchorSerialize` (in Nightly builds, run with -Z macro-backtrace for more info)

How should I be dealing with this? Any idea what's going on?

Thanks in advance.

1
  • Maybe what I need to do is to make these types not export on the IDL? Is there a way to make certain types not be exported on the IDL?
    – c4b4d4
    Commented Oct 7 at 8:12

1 Answer 1

0

This looks like a known issue: https://github.com/coral-xyz/anchor/issues/2729#issuecomment-2155844009

Copying from the comment:

The reason for not supporting BTreeMap (or any of the map data structures) has to do with the nature of Solana programming. Beginners usually try to use a global map for everything (especially eth people), which is almost always a worse choice than using PDAs

3
  • Yeah, been on that thread before. That comment drives me crazy tho, disabling something just because beginners don't use it properly? >_<
    – c4b4d4
    Commented Oct 23 at 17:17
  • If you really want to do it, you could just wrap BTreeMap in a newtype and implement AnchorSerialize / AnchorDeserialize by hand
    – Jon C
    Commented Oct 24 at 17:01
  • Decided to no longer support it, it will be a pain if I just keep dragging it. Will probably just keep using it internally, but not in accounts that need to be reflected in the IDL
    – c4b4d4
    Commented Nov 8 at 16:26

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.