Move shared candid types to a separate crate

Hey there!

In the ic-stable-memory library, I’ve implemented a bunch of traits for IC-specific types, such as Principal, Nat and Int. I’m importing them from candid 0.8.4 library.

Some users of ic-stable-memory have been reporting an error that if they use a different version of candid in their projects alongside ic-stable-memory, Rust won’t compile their code with an error stating that traits from ic-stable-memory are not implemented for, for example, Principal type they import from candid library. It seems like Rust sees these two types as completely different entities.

It seems that ic-cdk also has such an issue, where you have to use the same version of candid in order for it to work. Even if the types are not changed, if something new gets implemented in the candid library, everybody else have to bump their versions in order for everything to continue to work.

So, with that being said, I’d like to propose a simple solution for the team responsible for candid library.
Could you please move all shared types (mainly, these three) into a separate crate (candid-types or smth) that everybody can reference and that won’t be updated as frequently as candid?

1 Like

Yes, this is a known problem for Rust. It’s only a problem for major version change. If everybody is using 0.8.x, it should be fine. We try to keep major version change as few as possible, but with a major version bump, all the upstream crates has to be in sync with the new release. Unfortunately, all Rust crates work this way.

As for separating out some primitive types, the problem is that it creates cyclic dependency: Principal requires CandidType trait, and candid serialization also requires to use Principal types. In an earlier version of candid, the principal types is actually in a separate crate, but because of the cyclic dependency, we moved it back to Candid. Not sure if there is a better solution here.


This is exactly the topic I will investigate in Q2. Hopefully we will get some DX improvement around it.

63 hours until Q2. I will be watching the clock.