cbor icon indicating copy to clipboard operation
cbor copied to clipboard

Use `serde::ser::StdError` shim type rather than `std::error::Error`

Open cbeck88 opened this issue 5 years ago • 2 comments

This is for alloc vs. std modes compatibility, a code comment explains in detail the purpose of this, which is admittedly subtle.

After this commit, builds like

~/cbor$ cargo build --no-default-features --features=alloc,serde/std

succeed locally for me.


I'm evaluating using cbor in a large project, I think a patch like this would be super helpful to us.

The gist of it is, we have a bunch of SGX enclaves written in rust, and servers that pass messages to them in rust. I would like to use cbor/alloc in the enclaves to deserialize messages across the FFI boundary.

It would be great if no_std infra crates (that get used in both servers and enclacves) in our codebase can unconditionally select cbor/alloc, omit any reference to an std flag (to minimize configuration), and these crates can be consumed both by enclaves, and by servers that also rely on third party crates from crates.io that may enable serde/std. I think this patch will make that possible, I'm going to test it.

cbeck88 avatar Feb 15 '20 20:02 cbeck88

It looks like serde_json is instead using serde::de::StdError: https://github.com/serde-rs/json/blob/4bcc3625c34b4f9b6c76013b8a5afcaed5a1f1da/src/error.rs#L317

It probably is not a meaningful difference.

stevenroose avatar May 22 '20 09:05 stevenroose

What is a meaningful difference though is that serde_json is only providing the source method on the std feature. Instead of only doing that for the Error::Io variant.

I think matching as closely as possible what serde_json does, would be a good idea. Given that serde_json is maintained by the same folks as serde itself.

stevenroose avatar May 22 '20 09:05 stevenroose