Casting to EnumerableSet

I have a function with a parameter uint[] that I assign to a state variable, but I must change from array to EnumerableSet.

I can't take an EnumerableSet as a parameter, is this correct?
Is there anyway to cast an array to an EnumerableSet?
Or should I iterate over the array and add to the set one value at a time?

Thank you


pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

contract Storage {
    using EnumerableSet for EnumerableSet.UintSet;

    EnumerableSet.UintSet private mySet;

    constructor() {}

    function acceptsArray(uint[] memory myArray) public {
        // convert from array to EnumerableSet
    }
}

It's not possibly to cast directly to enumerable set. You would need to iterate over the array and add one at a time.

1 Like