To use a Principal
as key of a StableBTreeMap
I have to create a custom struct.
#[derive(CandidType, Deserialize, Clone, PartialOrd, Ord, Eq, PartialEq)]
pub struct StablePrincipal(pub(crate) Principal);
pub type StableControllerId = StablePrincipal;
impl From<&Principal> for StablePrincipal {
fn from(principal: &Principal) -> Self {
StablePrincipal(*principal)
}
}
It works as expected, I can convert StablePrincipal::from(principal
) and use the stable structure but, how can I defer the principal - how can I achieve the other way around?
Tried my_stable_principal.0
but got an issue
type `candid::Principal` cannot be dereferenced
Trie `my_stable_principal.into() but got an issue
the trait `From<&StablePrincipal>` is not implemented for `candid::Principal`
Tried to implement a Defer
trait but did not make it neither.
More a Rust noob question than related to the IC, still any help would be appreciated.