Skip to content
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

try_into does not work with never rust versions #38

Open
ytkimirti opened this issue Dec 1, 2022 · 1 comment
Open

try_into does not work with never rust versions #38

ytkimirti opened this issue Dec 1, 2022 · 1 comment
Assignees

Comments

@ytkimirti
Copy link

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

Reproduce

  • Go to examples/simple
  • Set the edition field of Cargo.toml to 2021
  • Run cargo check
   Compiling dgraph-tonic v0.10.2 (/Users/kimirti/tmp/dgraph-tonic)
    Checking simple v0.1.0 (/Users/kimirti/tmp/dgraph-tonic/examples/simple)
warning: use of deprecated associated function `chrono::TimeZone::ymd`: use `with_ymd_and_hms()` instead
  --> src/main.rs:73:18
   |
73 |         dob: Utc.ymd(1980, 1, 1).and_hms(23, 0, 0),
   |                  ^^^
   |
   = note: `#[warn(deprecated)]` on by default

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

#[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 selmeci self-assigned this Dec 7, 2022
@selmeci
Copy link
Owner

selmeci commented Dec 17, 2022

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

The same problem is reported here: rust-lang/rust-analyzer#10677.

I'm going to investigate it a little more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants