I have a issue that I have 3 enum in rust have similar value but it is different enities
pub enum IntentState { Created, Processing, Success, Fail }
pub enum ActionState { Created, Processing, Success, Fail }
pub enum TxState { Created, Processing, Success, Fail }
when I run extract-candid it will only generate IntentState - I assume candid will remove duplicate value and mapping to only one type
type IntentState = variant { Fail; Success; Processing; Created };
type ActionDto = record {
...
state : IntentState; // this should be ActionState
};
type TxDto = record {
...
state : IntentState; // this should be TxState
};
How to avoid this?
Candid uses structural typing, meaning that if two types have the same fields they are the same type to Candid, even if you call them differently.
candid-extractor just does its thing. If you want to have the different types listed, you need to write the .did file by hand, which I would recommend anyways.
3 Likes
Not a direct answer to your question but, looking at it from another way around, if the states are indeed similar, you can maybe approach it by having a common enum? This way by extension your DID file won’t reference a keyword that feels unrelated?
pub enum State { Created, Processing, Success, Fail }
pub type IntentState = State;
pub type ActionState = State;
pub type TxState = State;
Which would output:
type State = variant { Fail; Success; Processing; Created };
type ActionDto = record {
...
state : State;
};
type TxDto = record {
...
state : State;
};
Unless of course you really needs different enum, in that case never mind this post!
2 Likes