Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with candid_decode_one_allow_trailing for candid 0.9.0 and above #24

Open
wiyota opened this issue Oct 16, 2023 · 0 comments
Open

Comments

@wiyota
Copy link

wiyota commented Oct 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant