Skip to content

Misleading compiler error when using &strs instead of Strings with hostclient #117

Description

@wlcx

If you have a Response containing a &str...

#[derive(Serialize, Deserialize, Schema, Debug)]
pub struct InfoResponse<'a> {
    pub name: &'a str,
    pub mac: [u8; 6],
    pub fw_version: (u8, u8, u8),
}

... and try to use this in a std environment with a hostclient...

use std::net::Ipv4Addr;

use postcard_rpc::{host_client::HostClient, standard_icd::WireError};
use std::net::ToSocketAddrs;
use tally_rpc::rpc::{InfoEndpoint, InfoResponse};

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();

    let addr = (Ipv4Addr::new(10, 11, 12, 13), 1234)
        .to_socket_addrs()
        .unwrap()
        .next()
        .unwrap();
    let cli = HostClient::<WireError>::connect_tcp(addr).await;
    println!("connected");
    let info: InfoResponse = cli.send_resp::<InfoEndpoint>(&()).await.unwrap();
    println!("{:?}", info);
}

...the compiler error you get is misleading, complaining about WireErr:

error: implementation of `serde::de::Deserialize` is not general enough
  --> src/bin/tallycli.rs:18:30
   |
18 |     let info: InfoResponse = cli.send_resp::<InfoEndpoint>(&()).await.unwrap();
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `serde::de::Deserialize` is not general enough
   |
   = note: `WireError` must implement `serde::de::Deserialize<'de>`
   = note: ...but it actually implements `serde::de::Deserialize<'0>`, for some specific lifetime `'0`

error: implementation of `serde::de::Deserialize` is not general enough
  --> src/bin/tallycli.rs:18:34
   |
18 |     let info: InfoResponse = cli.send_resp::<InfoEndpoint>(&()).await.unwrap();
   |                                  ^^^^^^^^^ implementation of `serde::de::Deserialize` is not general enough
   |
   = note: `WireError` must implement `serde::de::Deserialize<'de>`
   = note: ...but it actually implements `serde::de::Deserialize<'0>`, for some specific lifetime `'0`

error: implementation of `serde::de::Deserialize` is not general enough
  --> src/bin/tallycli.rs:18:65
   |
18 |     let info: InfoResponse = cli.send_resp::<InfoEndpoint>(&()).await.unwrap();
   |                                                                 ^^^^^ implementation of `serde::de::Deserialize` is not general enough
   |
   = note: `WireError` must implement `serde::de::Deserialize<'de>`
   = note: ...but it actually implements `serde::de::Deserialize<'0>`, for some specific lifetime `'0`

error: could not compile `tool` (bin "tallycli") due to 3 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Q2 '25 TriageItems tracked as part of https://github.com/jamesmunns/postcard/issues/241

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions