Closed marxin closed 6 months ago
mapping: HashMap<u64, u64>,
Apparently, one possible solution would be using Rc<Mutex<HashMap<u64, u64>
.
Thanks for your report! In the helper function that is used for parsing collections, arguments get moved into the reader function on each iteration, and I’m unaware of a way to do this less restrictively than by requiring the Clone
trait. I’d be glad to see a PR if it is possible though :-)
Instead, I believe you should use parse_with
with a function that accepts &mut HashMap<u64, u64>
and returns a Vec<Item>
. (See #[binrw::parser]
.) The Rust compiler is more capable of reasoning about intrafunction lifetimes, and you presumably need some way to call whatever methods on HashMap
anyway to set up your mapping.
Thanks for the reply. Both approaches are feasible for my use case. Anyway, thank you for the nice library!
First of all, thanks for the great parsing library. Have a question: I'm writing a parser for DNS packets where DNS question section can contain a Question that references a previous one. Thus, I would like to keep a mapping in a parent object:
In the future, I would like to use and modify the
mapping
map in theparse_with
function. But I can't compile this code due to:Is it really needed the
Clone
attribute? Note the issue goes away if I changeitems: Vec<Item>
toitem: Item
.