rust-embedded-community/serde-json-core

Can't get code to compile, do you have a working example?

bentwire opened this issue · 1 comments

I'm trying to get the following to compile but it throws an error:

[derive(Serialize, Deserialize, Debug)]
pub struct StatusResponse {
    pub pressure_psi: i32,
    pub temperature_c: i32,
    pub panic_state: bool,
    pub power_state: bool,
}

impl StatusResponse {
    pub fn serialize(&self) -> &[u8] {
        serde_json_core::to_string(self).as_ref().unwrap().as_bytes()
    }
}
error[E0282]: type annotations needed
  --> src/vpc/comms.rs:38:9
   |
38 |         serde_json_core::to_string(self).as_ref().unwrap().as_bytes()
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `B`

I don't understand what it wants. From the examples I have found I don't need to pass anything else in to the to_string function... Does this crate work?

I was fighting with multiple versions of heapless apparently. I figured it out..