heapless icon indicating copy to clipboard operation
heapless copied to clipboard

Deserializing a string that exceeds the length: truncate?

Open gauteh opened this issue 1 year ago • 3 comments

Hi,

I would like to truncate or set as None, or somehow accept without Error a string that is longer than the capacity of the String. Or is there some other way to deal with this in serde that you know of?

Related to: https://github.com/japaric/heapless/issues/359

Regards, Gaute

gauteh avatar Sep 22 '23 15:09 gauteh

Bump. Any implementation of the FromIterator trait should never panic. We should probably settle on a better behavior in the future, like truncation.

Frostie314159 avatar Sep 25 '23 10:09 Frostie314159

Any implementation of the FromIterator trait should never panic.

I agree that this is not desirable, but I am curious, is this a requirement? I took a look at the documentation but did not see anything.

newAM avatar Oct 30 '23 23:10 newAM

These are two independent issues:

  • FromIterator from a too long iterator panics.
  • Serde deserialization return an error, doesn't panic.

This issue is about the 2nd, I guess?

IMO the default for deserializing a long string should be an error. Other behaviors (like truncating) should be opt-in. So I wouldn't change the current serde impls.

Truncating can be done with a wrapper, which doesn't necessarily have to be in the heapless crate. For example you can write your own parser and use the serde with attribute.

Dirbaio avatar Oct 30 '23 23:10 Dirbaio