fmt + clippy

This commit is contained in:
joeyahines committed 2021-10-09 14:00:49 -06:00
1 parent bb6f331c75
commit ef8918d517
5 files changed
+105 -49

No files matched your search

+5 -4
View File
@@ -1,5 +1,5 @@
use std::fmt::{Display, Formatter};
use num_bigint::BigUint;
use std::fmt::{Display, Formatter};
#[derive(Clone, Debug)]
pub enum ByteStreamError {
@@ -9,7 +9,7 @@ pub enum ByteStreamError {
impl Display for ByteStreamError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ByteStreamError::OutOfRange => write!(f, "Requested values out of range")
ByteStreamError::OutOfRange => write!(f, "Requested values out of range"),
}
}
}
@@ -33,14 +33,15 @@ pub struct ByteStream {
data: Vec<u8>,
}
impl ByteStream {
pub fn get_bytes(&self, bit_ndx: usize, bit_count: usize) -> Result<Vec<u8>, ByteStreamError> {
let byte_ndx = bit_ndx / 8;
let bits_before = (bit_ndx % 8) as u8;
let bits_in_last_byte = ((bit_ndx + bit_count - bits_before as usize) % 8) as u8;
let byte_count = ((bit_count as f32) / (8.0)).ceil() as usize;
let bytes_needed = if (bits_before as usize + bit_count) % 8 != 0 && !(bits_before as usize + bit_count < 8){
let bytes_needed = if (bits_before as usize + bit_count) % 8 != 0
&& bits_before as usize + bit_count >= 8
{
byte_count + 1
} else {
byte_count