Trying to implement boundedVecs for an struct, but the compiler is telling me that I can´t Clone the struct because the StringLimit Constant doesn´t comply with the Clone Trait.

This is the definition of the constant under Config:

type StringLimit: Get<u32>;

And the following is the definition of the struct:

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct Details<Balance, AccountId, AssetId, BlockNumber, PollIndex, StringLimit: Get<u32>> {
    /// Poll id.
    pub poll_id: PollIndex,
    /// Account who created this poll.
    pub created_by: AccountId,
    /// Question for the poll.
    pub poll_question: BoundedVec<u8, StringLimit>,
    /// Option for the poll.
    pub poll_option_1: BoundedVec<u8, StringLimit>,
    /// Option for the poll.
    pub poll_option_2: BoundedVec<u8, StringLimit>,
    /// Option for the poll.
    pub poll_option_3: Option<BoundedVec<u8, StringLimit>>,
    /// Option for the poll.
    pub poll_option_4: Option<BoundedVec<u8, StringLimit>>,
    /// The number of poll options.
    pub options_count: u8,
    /// Info regrading stake on poll options.
    pub votes: Votes,
    /// Number of vote received.
    pub votes_count: u128,
    /// Currency of the poll.
    pub currency: AssetId,
    /// Status of the poll.
    pub status: PollStatus<BlockNumber>,
    /// Min balance to be able to vote on a poll.
    pub min_balance: Balance,

To make the code compile I needed to add Clone to the definition: type StringLimit: Get + Clone;

And to derive the trait at runtime level for the constant. I know that is not the correct solution. Do you know what the problem is?


1 Answer 1


You can use the CloneNoBound that will not impose the Clone bound on the generic types. One example is here in Cumulus.
There are a few more of these kind such as DefaultNoBound, EqNoBound, PartialEqNoBound and RuntimeDebugNoBound.

  • It worked with CloneNoBound, but i had to add Clone trait bond to almost every other type, like the following: #[derive(CloneNoBound, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] #[scale_info(skip_type_params(StringLimit))] pub struct PollDetails<Balance: Clone, AccountId: Clone, AssetId: Clone, BlockNumber: Clone, PollIndex: Clone, StringLimit: Get<u32>> { ... Is that right?
    – Xavier
    Commented Sep 8, 2023 at 11:31
  • Yep, since the other types actually need to be clonable. Commented Oct 8, 2023 at 10:15

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.