Fewer unwraps
This commit is contained in:
parent
8402a821ad
commit
9722dd8cb7
4 changed files with 32 additions and 21 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use anyhow::Context;
|
||||
|
||||
use crate::{constants::CHUNK_SIZE, torrent_metainfo::TorrentMetaV1Info};
|
||||
|
||||
const fn is_power_of_two(x: u64) -> bool {
|
||||
|
|
@ -123,6 +125,10 @@ impl Lengths {
|
|||
}
|
||||
Some(ValidPieceIndex(index))
|
||||
}
|
||||
pub fn try_validate_piece_index(&self, index: u32) -> anyhow::Result<ValidPieceIndex> {
|
||||
self.validate_piece_index(index)
|
||||
.with_context(|| format!("invalid piece index {index}"))
|
||||
}
|
||||
pub const fn default_piece_length(&self) -> u32 {
|
||||
self.piece_length
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue