-
-
Notifications
You must be signed in to change notification settings - Fork 826
Make it easier to write cross-platform code with serde #1594
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
Comments
Note on why |
I realized this is basically a repost of this: #1567 |
I guess this might be mooted if the lang team does this? rust-lang/rust#62502 |
I believe this is fixed with the reexports in 1.0.100: Data formats can provide the right Error impl whether or not Serde is built with "std" by writing: impl serde::ser::StdError for MySerError {}
impl serde::de::StdError for MyDeError {} |
Right now
serde
supportsno_std
in that it has anstd
feature, and analloc
feature, and it supports having neither of them turned on.But, if
std
andalloc
feature are both used, it usually causes build failures.This is because there is an interface change at the following lines:
My use case is that I am working on servers that contain SGX enclaves. The server (untrusted) part can use
std
because it has the OS available, but the enclave (trusted) part, cannot usestd
, because there is no trusted OS inside the enclave.In principle, it should be very convenient to use serde to pass messages between the server and the enclave, because it avoids adding more build steps for serialization, and ensures a single-source-of-truth for the serialization schema. And there's no reason that serde should not work in the enclave.
(There is the issue of
std::collections::HashMap
not being available outside of std but this is not a problem.)The real problem is that
std::error::Error
does not exist incore
, because the devs have declined to move it there.An alternate solution is to use the
failure
crate instead ofstd::error
module, which provides the same functionality with some improvements, and without requiringstd
.It would also be great if there were a way to use
serde
so that the interface does not break betweenstd
andalloc
settings. Why usestd::error
at all? Can we just useDebug + Display
in all cases?The current case basically means that anyone who wants to use
serde
in a cross-platform crate that works with bothstd
andnostd
contexts, must exposestd
andalloc
features mirroringserde
, and if these features get confused at any point, the build fails in strange ways.It would be a lot simpler to write cross platform code if, code that doesn't need
std
can simply omitstd
, and then be used as a dependency of code that does needserde/std
(for example to serialize a hash map), without causing a build failure within serde. This would prevent serde dependency from infecting the entire project withstd
andalloc
feature flags.Is there any interest from developers in reconciling the differences between these two lines?
I am strongly considering patching serde in my project to always use the
Debug + Display
version even whenstd
is on, because I think all my dependencies will still work fine -- theerror::Error
trait is mostly useless.The text was updated successfully, but these errors were encountered: