deconstruct newtype rather than index tuple

This commit is contained in:
Quaternions 2025-03-20 19:55:01 -07:00
parent 5343c28701
commit 85537484d1

@ -517,12 +517,12 @@ pub struct BlockInfo{
length:u32,
}
impl FileHeader{
pub fn block_info(&self,block_id:BlockId)->Result<BlockInfo,Error>{
if self.block_positions.len() as u32<=block_id.0{
return Err(Error::InvalidBlockId(block_id));
pub fn block_info(&self,BlockId(block_id):BlockId)->Result<BlockInfo,Error>{
if self.block_positions.len() as u32<=block_id{
return Err(Error::InvalidBlockId(BlockId(block_id)));
}
let start=self.block_positions[block_id.0 as usize].0;
let end=self.block_positions[block_id.0 as usize+1].0;
let BlockPosition(start)=self.block_positions[block_id as usize];
let BlockPosition(end)=self.block_positions[block_id as usize+1];
Ok(BlockInfo{start,length:end-start})
}
}