alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
758 stars 131 forks source link

[BugFix] Use Cow<'a, str> to be compatible with serde_json::from_reader #668

Closed wtdcode closed 2 months ago

wtdcode commented 2 months ago

Motivation

Fix #667

Solution

As title, use Cow<'a, str> to be compatible with serde_json::from_reader

PR Checklist

I don't see any possible breaking changes because previously it is not working. Besides, it shouldn't incur any performance penalty because from general from_str the data is still borrowed.

wtdcode commented 2 months ago

Found this:

    fn visit_str<E>(self, _v: &str) -> Result<Self::Value, E>
    where
        E: serde::de::Error,
    {
        // `from_reader` copies the bytes into a Vec before calling this
        // method. Because the lifetime is unspecified, we can't borrow from it.
        // As a result, we don't support `from_reader`.
        Err(serde::de::Error::custom(
            "Using serde_json::from_reader is not supported. Instead, buffer the reader contents into a string, as in alloy_json_abi::JsonAbi::load.",
        ))
    }

Looks like I need to fix more code.

wtdcode commented 2 months ago

Give up.