BoundedVec is a vector where the length of the queue is always bounded, which is better than Vec for storage because it has a defined a maximum length.
I recommend this StackExchange questions to learn the difference between BoundedVec and Vec: When to use BoundedVec
vs. WeakBoundedVec
vs. Vec
?
Vec is okay to use in the runtime, but never to put into storage, since it is unbounded by definition.
In my Smart Contract I want to store a struct that contains a Vec.
What is the best practice here?
- Store the Vec like in the ink! documentation example: https://use.ink/basics/storing-values
- Import a BoundedVec (how?) like in the FRAME pallets: https://substrate.stackexchange.com/a/1005/2762
- Create my own data type like is explained here in the ink! documentation: https://use.ink/datastructures/custom-datastructure#generic-storage-fields