Closed kylecarow closed 7 months ago
I'm wondering if I'll run into trouble anyway, considering the docs for csv::Reader::deserialize
that I linked above state that it requires the trait DeserializeOwned
... not sure.
Realized this is not possible given these SO posts and is not specific to this crate.
Howdy! Thanks for the useful crate! Looking forward to using it. I'm still somewhat a Rust novice, so bear with me.
Summary
I'm trying to understand why deriving
Deserialize
on a reference to a quantity doesn't work (or, perhaps, why quantities implDeserialize
but references to quantities do not). Is this something that could be changed? I don't really want to implDeserialize
myself, as I expect to add more fields and it would be a maintenance headache. Or, is there a better way to structure my code?Context
I have a struct
Cycle
that containsVec
s of quantities, and another structCycleElement
that ought to hold one index of elements from aCycle
.CycleElement
can also serve as a way of constructing aCycle
bypush
ing them sequentially - see the testbuild_cycle
below.I am unable to derive
Deserialize
onCycleElement
, as it contains references to quantities, rather than owned quantities. I need to implDeserialize
onCycleElement
in order forcsv
serde to work, see the example here which requires the record struct to implDeserialize
.Error
Code
Below is a minimal reproducible example that refuses to compile. Remove the
Deserialize
derive onstruct CycleElement
and it works fine, but would become incompatible withcsv
serde. The tests are just there to make it easier to see how this code works, they don't really test anything.main.rs
:Cargo.toml
: