-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I have a question about Enum variants. Default case works perfectly:
#[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum SignerKey {
SIGNER_KEY_TYPE_ED25519(uint256), // match with "0"
SIGNER_KEY_TYPE_PRE_AUTH_TX(uint256), // match with "1"
SIGNER_KEY_TYPE_HASH_X(uint256), // match with "2"
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_repr, Deserialize_repr)]
#[repr(i32)]
pub enum SignerKeyType {
SIGNER_KEY_TYPE_ED25519 = 0,
SIGNER_KEY_TYPE_PRE_AUTH_TX = 1,
SIGNER_KEY_TYPE_HASH_X = 2,
}But sometimes we have unusual Enums, something like that:
pub enum SignerKeyType {
SIGNER_KEY_TYPE_ED25519 = 2,
SIGNER_KEY_TYPE_PRE_AUTH_TX = 5,
SIGNER_KEY_TYPE_HASH_X = -6,
}Of course this doesn`t works and we cant match received values with SignerKey variants. Do we have any ability to mark it explicit? Something about that in my mind:
pub enum SignerKey {
#[serde(compare_with = SignerKeyType::SIGNER_KEY_TYPE_PRE_AUTH_TX)]
SIGNER_KEY_TYPE_ED25519(uint256), // match with "2"
#[serde(compare_with = SignerKeyType::SIGNER_KEY_TYPE_ED25519)]
SIGNER_KEY_TYPE_PRE_AUTH_TX(uint256), // match with "5"
#[serde(compare_with = SignerKeyType::SIGNER_KEY_TYPE_HASH_X)]
SIGNER_KEY_TYPE_HASH_X(uint256), // match with "-6"
#[serde(default_case)]
Void, // pick this if previous variants doesn`t match
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels