m4b / goblin

An impish, cross-platform binary parsing crate, written in Rust
MIT License
1.19k stars 160 forks source link

Alternative owned data version? #375

Closed mlgiraud closed 3 months ago

mlgiraud commented 1 year ago

Hi, are there any plans on providing an alternative API where the data is not Borrowed by the goblin objects? The current api is problematic, when i want to for example save an Elf object that was parsed from some data in a struct. This then requires the custom struct to pass through the lifetime annotation, and also the data from which the elf object was parsed needs to be immutably borrowed for as long as this overarching struct lives. I would find it very useful to have an API where there is no lifetime annotation and instead the goblin objects simply take ownership of the data buffer. Any thoughts on this? Or am i overlooking some easy solution to this problem?

m4b commented 3 months ago

sorry for the delay; there are no plans at the moment for adding an owned version; the main issue is that the string table is zero-copy and returns out references to the underlying data that backs it; there might be some mechanism where we can provide ownership with the same structs, but in general this is hard in rust imho. if you end up doing something interesting, feel free to post your solution here.

closing this for now as there is no plans on adding an owned version