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

Color deserialization - Bincode does not support the serde::Deserializer::deserialize_any method #603

Closed
pbellchambers opened this issue Sep 17, 2021 · 2 comments · Fixed by #604

Comments

@pbellchambers
Copy link

Describe the bug
Since the 0.21.0 release and the new deserialize implementation for Color, there has been a compatibility issue with Bincode because it expects the deserialize implementation to tell it what type of data to expect and doesn't support "deserialize_any".

#576

https://github.com/crossterm-rs/crossterm/blob/master/src/style/types/color.rs (line 293)

Given the new color function expects to deserialize strings, ansi, and rgb values, not sure how to solve. Perhaps use deserialize_str for all, and handle parsing in the visitor, is that possible/sensible?

To Reproduce
Steps to reproduce the behavior:
Use bincode to serialize / deserialize a crossterm Color, results in the below error:
Bincode does not support the serde::Deserializer::deserialize_any method

Expected behavior
Deserializing with bincode should work successfully.

OS

  • All

Terminal/Console

  • All
@TimonPost
Copy link
Member

When implementing Deserialize, you should avoid relying on Deserializer::deserialize_any unless you need to be told by the Deserializer what type is in the input. Know that relying on Deserializer::deserialize_any means your data type will be able to deserialize from self-describing formats only, ruling out Bincode and many others.

https://docs.serde.rs/serde/trait.Deserializer.html#tymethod.deserialize_any

@TimonPost
Copy link
Member

TimonPost commented Sep 18, 2021

So I have it working when serializing Color::RGB to rgb_(r,g,b) and Color::Ansi to ansi_(a). Although it does feel hacky it might be a valid solution to only use the string deserializer. Im not sure how deserialize_enum works.

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

Successfully merging a pull request may close this issue.

2 participants