1

I'm using anchor to build solana program. In account struct, I have multi-dimensional vector.

#[max_len(2,50)]
element: Vec<Vec<MyType>>,

In this case, what is the meaning of (2, 50)?

I want to element to be like this:

element = vec![vec![x,x,...50x], vec![x,x, ...50x]];

In this case, what is the right form of these two?

#[max_len(2,50)]
#[max_len(50,2)]

EDIT

#[max_len(50)]
element: [Vec<MyType>; 2]

In this case, each two vec can contain 50 elements? Totally, element can contain 100 elements?

1 Answer 1

0

The documentation for max_len says:

For types that have a variable size like String and Vec, it is necessary to indicate the size by the max_len attribute. For nested types, it is necessary to specify a size for each variable type (see example).

Followed by:

    #[max_len(10, 5)]
    pub nested: Vec<Vec<u8>>,

Which goes Vec by Vec, so that would create enough space for 10 vecs with 5 u8s each.

Taken from https://docs.rs/anchor-lang/latest/anchor_lang/derive.InitSpace.html

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.