Rust is complaining in function read_toc that header is borrowed and does not live long enough (line self.toc = Some(header.decode(&mut data).unwrap());).
I do not understand why header keeps borrowed, because function decode returns a new Toc object, which does not have any dependencies to header.
Can you include the definition of Toc? From the definition of Decompressor, it seems like it includes a reference to external data, and the lifetime of that reference is getting tied to the lifetime of Header because of how the inference rules work. Adding the lifetimes explicitly gives this signature for decode:
As a side note, I’m having trouble tracking what data is supposed to live where. I recommend that you consider replacing some of these references with either Arcs for shared ownership or cloned copies for full ownerhsip. Options particularly feels like something that’s unlikely to benefit much from being borrowed instead of owned.
You have a self-referential struct: decompressor.toc contains File that sits in the decompressor. Rust's borrow checker can't guarantee safety of this.
Rust references (temporary borrows) are not general-purpose method of referencing objects as you'd in Java or in C with pointers. By design, they can't be used to store anything "by reference". They can't form mutable parent-child relationships and come with very specific semantics of making things temporary, locked and bound to a scope. If you don't intend to make things unmovable and restrictive, don't use references, especially don't use references in structs.
If you need parent-child relationships, use Arc<Mutex<T>> rather than &mut T. But usually Rust idiomatic code avoids parent-child relationships in data. You can pass the parent to methods explicitly where it's needed, or rearrange data so that the parent is not needed.
Try not using references in structs at all. If you want to store something by reference, the correct type for that is Box or Arc.
Never use &Vec<T>. That type doesn't make sense (you're asking for growable vector, but then you're asking for immutable access that prevents it from growing). In function arguments use &[T].