Serde: Handling uuid::Uuid

Created on 14 May 2016  路  2Comments  路  Source: serde-rs/serde

I was trying to serialize a struct with uuid in it and received the following error.

src/Book/model.rs:3:45: 3:45 error: the trait bound `uuid::Uuid: Book::model::_IMPL_DESERIALIZE_FOR_Book::_serde::Deserialize` is not satisfied [E0277]
src/Book/model.rs:3 #[derive(Queryable, Serialize, Deserialize)]
                                                                ^
src/Book/model.rs:3:45: 3:45 note: in this expansion of try! (defined in <std macros>)
src/Book/model.rs:3:45: 3:45 note: in this expansion of #[derive_Deserialize] (defined in src/Book/model.rs)
src/Book/model.rs:3:45: 3:45 note: in this expansion of include!
src/Book/model.rs:3:45: 3:45 help: run `rustc --explain E0277` to see a detailed explanation
src/Book/model.rs:3:45: 3:45 error: the trait bound `uuid::Uuid: Book::model::_IMPL_DESERIALIZE_FOR_Book::_serde::Deserialize` is not satisfied [E0277]
src/Book/model.rs:3 #[derive(Queryable, Serialize, Deserialize)]
                                                                ^

Here is the struct

use uuid::Uuid;

#[derive(Queryable, Serialize, Deserialize)]
pub struct Book {
    pub book_id: Uuid,
    pub book_abbr: Option<String>,
    pub book_volume: Option<String>,
    pub book_name: String,
    pub book_altname: Option<String>,
}

Is there something that i am missing?

Thanks

support

Most helpful comment

You need to enable the serde feature flag on the uuid crate in order for it to provide Serialize and Deserialize impls.

All 2 comments

You need to enable the serde feature flag on the uuid crate in order for it to provide Serialize and Deserialize impls.

In case you're wondering, like I did, how to specify it, here's an example:

uuid = { version = "0.7", features = ["v4", "serde"] }

Have a look at the documentation: https://docs.rs/uuid/0.7.1/uuid/#dependencies.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dtolnay picture dtolnay  路  3Comments

kleimkuhler picture kleimkuhler  路  3Comments

dtolnay picture dtolnay  路  3Comments

Yamakaky picture Yamakaky  路  3Comments

dtolnay picture dtolnay  路  4Comments