Skip to content

try_into does not work with never rust versions #38

Description

@ytkimirti

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)
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions