Issues with postcard/serde

I have this example code:

use postcard;
use serde;
pub fn main()
    #[derive(Debug, serde::Serialize, serde::Deserialize)]
    struct Object
        x       : u16,
        y       : u16,

    //const VERSION: &'static str = "0.0.1";
    const VERSION: f32= 0.1;

    let rect = Object{x: 10, y: 20};

    fn save(object: &Object)
        let data = postcard::to_vec(object);

in this line let data = postcard::to_vec(object); I am getting an error that states:

20 |         let data = postcard::to_vec(object);
   |                    ^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `B` declared on the function `to_vec`

Not too sure why I am getting this issue?

Does using postcard::to_stdvec (instead of postcard::to_vec) help?

It doesn't seem to even exist?

I imported both serde and postcard like this in the Cargo.toml file:

postcard = "1.0.4"
serde = "1.0.157"


postcard = { verison = "1.0.4", features = ["use-std"] }
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.