Serde: Question about Zero-Copy Deserialization lifetime error

Created on 1 Nov 2017  路  4Comments  路  Source: serde-rs/serde

Why am I getting this lifetime error?

Thanks!

support

All 4 comments

Thanks, I got it working for structs with #[serde(borrow)] but how can I make it work for enums?

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Msg<'a> {
    #[serde(borrow)]
    System(SystemTransaction<'a>),
    #[serde(borrow)]
    Item(ItemTransaction<'a>),
}
error: proc-macro derive panicked
help: message: 2 errors:
    # unknown serde variant attribute `borrow`
    # unknown serde variant attribute `borrow`

@Boscop this is a field attribute, not a variant one:

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Msg<'a> {
    System(#[serde(borrow)] SystemTransaction<'a>),
    Item(#[serde(borrow)] ItemTransaction<'a>),
}

929 tracks making it work for newtype variants. I would love a PR if anyone has time to implement it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dtolnay picture dtolnay  路  3Comments

dtolnay picture dtolnay  路  3Comments

kleimkuhler picture kleimkuhler  路  3Comments

dtolnay picture dtolnay  路  3Comments

dtolnay picture dtolnay  路  4Comments