Skip to content

Error with candid_decode_one_allow_trailing for candid 0.9.0 and above #24

@wiyota

Description

@wiyota

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions