Closed crzysdrs closed 6 months ago
By providing the lifetime of the Sections struct to the closure, the user can hold references to the data if neccesary.
Motivating Example:
use gimli::write::{DwarfUnit, EndianVec, Sections}; fn main() { let encoding = gimli::Encoding { format: gimli::Format::Dwarf32, version: 5, address_size: 8, }; // Create a container for a single compilation unit. let mut dwarf = DwarfUnit::new(encoding); let mut sections = Sections::new(EndianVec::new(gimli::LittleEndian)); // Finally, write the DWARF data to the sections. dwarf.write(&mut sections).unwrap(); { let mut vec: Vec<&[u8]> = vec![]; sections .for_each(|_id, data| { vec.push(data.slice()); Result::<(), ()>::Ok(()) }) .unwrap(); println!("{}", vec.len()); } { let mut vec: Vec<&mut _> = vec![]; sections .for_each_mut(|_id, data| { vec.push(data); Result::<(), ()>::Ok(()) }) .unwrap(); println!("{}", vec.len()); } }
By providing the lifetime of the Sections struct to the closure, the user can hold references to the data if neccesary.
Motivating Example: