Why can I auto derive serde::Deserialize
for my WidgetValue
enum, but not for a struct made up entirely of WidgetValue
fields?
This seems counterintuitive to me.
EDIT: For various reasons, I'm using the WidgetValue enum because I'd like to send different values through a function with the same type signature. See Vector store mixed types of data in Rust, How do I create a heterogeneous collection of objects?, etc.
serde = { version = "1.0.126", features = ["derive"] }
//works fine
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub enum WidgetValue{
Integer32(i32),
Unsized32(u32),
CString(&'static str),
}
//lifetime error
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub struct DraggableInfo{
parent: WidgetValue,
index: WidgetValue,
draggable_id: WidgetValue,
}
Error:
cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements