Hello ICP community and DFINITY developers,
I’m working with a Rust canister and using Candid to encode/decode a vector of enums in the Init Args for the canister. My type definitions are:
#[derive(Deserialize, Serialize, CandidType, Debug)]
pub struct InitArgs {
pub allowed_reward_tokens: Vec<TokenSymbol>,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Serialize,
Deserialize,
CandidType,
minicbor::Encode,
minicbor::Decode,
)]
pub enum TokenSymbol {
#[n(0)]
ICP,
#[n(1)]
TOKEN2,
#[n(2)]
TOKEN3,
#[n(3)]
TOKEN4,
#[n(4)]
TOKEN5,
}
I’m trying to encode and decode values like:
vec { variant { ICP }; variant { TOKEN1 }; variant { TOKEN2 }; variant { TOKEN3 } }
Issue:
When I encode and decode this vector, only the first variant seems to be recognized/used. The rest are ignored or not decoded as expected.
So I decided to print this field:
ic_cdk::println!(
"tokens: {:#?}",
init_args.tokens
);
The output of print command:
[ICP, ICP, ICP, ICP,]
So it always prints the repeated first arg
Has anyone encountered a similar issue? Any insights or suggestions would be greatly appreciated!