ic-stable-memory icon indicating copy to clipboard operation
ic-stable-memory copied to clipboard

Error with candid_decode_one_allow_trailing for candid 0.9.0 and above

Open wiyota opened this issue 2 years ago • 0 comments

Hello @seniorjoinu.

In candid version 0.9.0 or later, an error occurs in candid_decode_one_allow_trailing when trying to implement AsDynSizeBytes for a dynamic size enum that satisfies StableType, CandidType and Deserialize The following error occurs in candid_decode_one_allow_trailing.

#[derive(StableType, CandidType, Deserialize)]]
pub struct DetailsV001 {
    pub name: String,
    pub description: String,
    pub tag_ids: Vec<u64>,
}

#[derive(StableType, CandidType, Deserialize, CandidAsDynSizeBytes)]]
pub enum Details {
    V001(DetailsV001),
}

then,

error[E0277]: the trait bound `Details: candid::types::CandidType` is not satisfied
   --> src/backend/src/something.rs:14:47
    |
14  | #[derive(StableType, CandidType, Deserialize, CandidAsDynSizeBytes)]
    |                                               ^^^^^^^^^^^^^^^^^^^^ the trait `candid::types::CandidType` is not implemented for `Details`
    |
    = help: the following other types implement trait `candid::types::CandidType`:
              bool
              isize
              i8
              i16
              i32
              i64
              i128
              usize
            and 131 others
note: required by a bound in `candid_decode_one_allow_trailing`
   --> /Users/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ic-stable-memory-0.4.4/./src/encoding/dyn_size.rs:118:26
    |
116 | pub fn candid_decode_one_allow_trailing<'a, T>(bytes: &'a [u8]) -> Result<T>
    |        -------------------------------- required by a bound in this function
117 | where
118 |     T: Deserialize<'a> + CandidType,
    |                          ^^^^^^^^^^ required by this bound in `candid_decode_one_allow_trailing`
    = note: this error originates in the derive macro `CandidAsDynSizeBytes` (in Nightly builds, run with -Z macro-backtrace for more info)

The same error occurred when I manually implemented AsDynSizeBytes.

This does not happen with candid 0.8.4.

wiyota avatar Oct 16 '23 11:10 wiyota