selmeci / dgraph-tonic

Async/Sync gRPC client for Dgraph DB
MIT License
83 stars 8 forks source link

try_into does not work with never rust versions #38

Open ytkimirti opened 1 year ago

ytkimirti commented 1 year ago

Rust newbie here. I was trying out sample code but Response::try_into throws compilers error on newer rust editions.

Reproduce

warning: use of deprecated associated function chrono::Date::<Tz>::and_hms: Use and_hms_opt() instead --> src/main.rs:73:34 | 73 | dob: Utc.ymd(1980, 1, 1).and_hms(23, 0, 0), | ^^^^^^^

error[E0277]: the trait bound All: From<Response> is not satisfied --> src/main.rs:136:25 136 let ppl: All = resp.try_into().expect("JSON"); ^^^^^^^^ the trait From<Response> is not implemented for All
= note: required for `Response` to implement `Into<All>`
= note: required for `All` to implement `TryFrom<Response>`
= note: required for `Response` to implement `TryInto<All>`

For more information about this error, try rustc --explain E0277. warning: simple (bin "simple") generated 2 warnings error: could not compile simple due to previous error; 2 warnings emitted


I couldn't really understand why this is happening. The type `All` implements `serde::Deserialize`
```rust
#[derive(Debug, Serialize, Deserialize)]
struct All {
    all: Vec<Person>,
}

And Response implements the try_into function.

impl Response {
    ///
    /// Try deserialize response JSON data into T
    ///
    pub fn try_into<'a, T>(&'a self) -> Result<T, Error>
    where
        T: de::Deserialize<'a>,
    {
        let result: T = serde_json::from_slice(&self.json)?;
        Ok(result)
    }
selmeci commented 1 year ago

Hi, thank you for the report, but it looks like internal Rust's compile problem.

The same problem is reported here: https://github.com/rust-lang/rust-analyzer/issues/10677.

I'm going to investigate it a little more.