borsh-rs icon indicating copy to clipboard operation
borsh-rs copied to clipboard

Skip adding the where clause to avoid triggering overflow

Open Arrowana opened this issue 1 year ago • 4 comments

Problem

#[derive(BorshSerialize, BorshDeserialize)]
enum A {
    B,
    C {
        d: Vec<A>,
    },
}

gives overflow evaluating the requirement A: BorshDeserialize or BorshSerialize

Idea

Allow skipping adding to the where clause with an attribute to allow edge cases to function.

I am told this could help https://github.com/rust-lang/rust/issues/48214 but there is currently no way to achieve the same effect "working for recursive data structure" by determining automatically which where clause to add in the proc_macro

Not complete yet as this attribute only has an effect for an enum

Related issues

https://github.com/near/borsh-rs/issues/7

Arrowana avatar Jul 27 '22 02:07 Arrowana

Please, add tests

Sorry, i did have the file locally but forgot to add it. Pushed now

Please note that I am waiting for your agreement on the broad feature before I'll add it to other types.

Arrowana avatar Jul 27 '22 10:07 Arrowana

@Arrowana The reason I asked for the test is to see how this is expected to be used.

Reading https://github.com/near/borsh-rs/issues/7#issuecomment-765582816:

serde, can handle this case, btw

I wonder how they achieved that and whether it is possible to do here, so we don't need to have this attribute.

frol avatar Jul 27 '22 12:07 frol

@Arrowana The reason I asked for the test is to see how this is expected to be used.

Reading #7 (comment):

serde, can handle this case, btw

I wonder how they achieved that and whether it is possible to do here, so we don't need to have this attribute.

I looked at this user repositories, i found this https://github.com/near/borsh-rs/pull/96#issuecomment-1196652786 MachineValue is recursive

This is also my current workaround, manual trait implementation, just seems to be a lot of redo.

I would much prefer a solution that doesn't require the attribute but i just don't know how or if it is feasible at all.

Arrowana avatar Jul 27 '22 12:07 Arrowana

I would much prefer a solution that doesn't require the attribute but i just don't know how or if it is feasible at all.

It is possible, serde handles it. It's definitely more of an extensive process which I had started previously but somewhat abandoned since I didn't have the bandwidth. This is somewhat related to #41 and the issue that points this out is #7

austinabell avatar Jul 27 '22 12:07 austinabell

I think this PR is stalled and is not required anymore, so I am closing it.

frol avatar Jan 27 '23 11:01 frol