Trait "AbiDecode" is not implemented for type "CustomStruct

I’ve read in the docs somewhere that with the new v1 encoding, there’s an option of implementing custom encoding for structs. If none is available, the default is used. I’m getting the error: Trait “AbiDecode” is not implemented for type “CustomStruct”. where CustomStruct is a two-field struct. Unsure why the compiler is failing to decode this passed around functions, but how can I implement AbiDecode for this struct?

The struct itself is very simple:

struct CustomStruct {
    pub value: u256,
    pub is_neg: bool,
}

with some trait implementations for From, core::ops::Eq, core::ops::Ord and some struct public methods that operate on the field data in the structs

Hey @theAusicist, can you please try this solution and see if it works?

Hi @Nazeeh21 unfortunately, the solution above is for the Rust SDK. The error in question I’ve raised above pertains to the Sway compiler being unable to compile the code itself with the following error:

Trait “AbiDecode” is not implemented for type “CustomStruct”

The struct itself has some trait implementations for From, core::ops::Eq, core::ops::Ord and some struct public methods that operate on the field data in the structs.

The error happens during a cross-contract call.

// Contract A
fn some_call() -> (u64, CustomStruct, u64, bool) {
...
}

// Contract B
fn call_contract_a() {
    let (one, _, three, four) = contr_a.some_call(); // doesn't error out 
    
    // errors out at compile time because we "actually" want the value of "CustomStruct"
    let (one, two, three, four) = contr_a.some_call(); 
}

I can confirm this wasn’t an issue at v0.49.3, the previous forc version I’d use. Upgrading to v0.60.0 changed that.

Okay, let me check with the team and get back to you

1 Like

We are considering it as a bug for now and the team is working on it. You can follow up on the progress here.

1 Like

this works.

Manually importing “CustomStruct” seems to do the trick.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.