refine BinRead Args tech

This commit is contained in:
Quaternions 2025-03-20 20:06:05 -07:00
parent 85537484d1
commit 77af5e386a

@ -390,12 +390,8 @@ struct EventChunkHeader{
num_events:u32, num_events:u32,
} }
// first time I've managed to write BinRead generics without this stupid T::Args<'a>:Required thing blocking me // binread args tech has been further refined
fn read_data_into_events<'a,R:BinReaderExt,T>(data:&mut R,events:&mut Vec<T>,num_events:usize)->binrw::BinResult<()> fn read_data_into_events<'a,R:BinReaderExt,T:binrw::BinRead<Args<'a>=()>>(data:&mut R,events:&mut Vec<T>,num_events:usize)->binrw::BinResult<()>{
where
T:binrw::BinRead,
T::Args<'a>:binrw::__private::Required,
{
// there is only supposed to be at most one of each type of event chunk per block, so no need to amortize. // there is only supposed to be at most one of each type of event chunk per block, so no need to amortize.
events.reserve_exact(num_events); events.reserve_exact(num_events);
for _ in 0..num_events{ for _ in 0..num_events{
@ -403,11 +399,7 @@ where
} }
Ok(()) Ok(())
} }
fn read_data_into_events_amortized<'a,R:BinReaderExt,T>(data:&mut R,events:&mut Vec<T>,num_events:usize)->binrw::BinResult<()> fn read_data_into_events_amortized<'a,R:BinReaderExt,T:binrw::BinRead<Args<'a>=()>>(data:&mut R,events:&mut Vec<T>,num_events:usize)->binrw::BinResult<()>{
where
T:binrw::BinRead,
T::Args<'a>:binrw::__private::Required,
{
// this is used when reading multiple blocks into a single object, so amortize the allocation cost. // this is used when reading multiple blocks into a single object, so amortize the allocation cost.
events.reserve(num_events); events.reserve(num_events);
for _ in 0..num_events{ for _ in 0..num_events{