You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ser::Error and de::Error traits conditionally require a std::error::Error bound when serde is compiled with the std feature (enabled by default).
This can be problematic for crates offering Serializers or Deserializers that conditionally work in no-std environments, because they can't tell internally whether serde is pulled in with its std feature or not (this can also happen when including a library like serde-test as a dev dependency).
In a future with a unified std this might just be a non-issue, but is a bit of a head-scratcher at the moment. Some work-arounds I've thought of that might help crates in this position are:
Offer some newtype structs in serde that always implement the appropriate error trait, but require a consistent bound from the type they wrap:
That internal bound could be something like fmt::Display, or some serde::ser::IntoError trait.
Offer a way to derive ser::Error or de::Error on caller structs that also handles std::error::Error if it's needed.
Offer a macro in serde like serde_if_std, so that crates could produce a nicer user-facing error message if their expectations of the error bounds don't align with serde's.
Note this one could be enough for an external crate to look at building derive support.
What do you think?
The text was updated successfully, but these errors were encountered:
Hi! 👋
The
ser::Error
andde::Error
traits conditionally require astd::error::Error
bound whenserde
is compiled with thestd
feature (enabled by default).This can be problematic for crates offering
Serializer
s orDeserializer
s that conditionally work in no-std environments, because they can't tell internally whetherserde
is pulled in with itsstd
feature or not (this can also happen when including a library likeserde-test
as a dev dependency).In a future with a unified
std
this might just be a non-issue, but is a bit of a head-scratcher at the moment. Some work-arounds I've thought of that might help crates in this position are:Offer some newtype structs in
serde
that always implement the appropriate error trait, but require a consistent bound from the type they wrap:That internal bound could be something like
fmt::Display
, or someserde::ser::IntoError
trait.Offer a way to derive
ser::Error
orde::Error
on caller structs that also handlesstd::error::Error
if it's needed.Offer a macro in
serde
likeserde_if_std
, so that crates could produce a nicer user-facing error message if their expectations of the error bounds don't align withserde
's.Note this one could be enough for an external crate to look at building derive support.
What do you think?
The text was updated successfully, but these errors were encountered: