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

Deserializing a string that exceeds the length: truncate? #379

Open
gauteh opened this issue Sep 22, 2023 · 3 comments
Open

Deserializing a string that exceeds the length: truncate? #379

gauteh opened this issue Sep 22, 2023 · 3 comments

Comments

@gauteh
Copy link

gauteh commented Sep 22, 2023

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: #359

Regards, Gaute

@Frostie314159
Copy link

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

@newAM
Copy link
Member

newAM commented Oct 30, 2023

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.

@Dirbaio
Copy link
Member

Dirbaio commented Oct 30, 2023

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.

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

No branches or pull requests

4 participants