Skip to content

Commit

Permalink
Fix warnings generated by clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
pverscha committed Sep 19, 2024
1 parent dc7e8b4 commit 5094fbf
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions text-compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ProteinText {
let mut bit_array = BitArray::with_capacity(input_string.len(), 5);
for (i, c) in input_string.chars().enumerate() {
let char_5bit: u8 =
*char_to_5bit.get(&(c as u8)).expect(&format!("Input character '{}' not in alphabet", c));
*char_to_5bit.get(&(c as u8)).unwrap_or_else(|| panic!("Input character '{}' not in alphabet", c));
bit_array.set(i, char_5bit as u64);
}

Expand All @@ -80,7 +80,8 @@ impl ProteinText {

let mut bit_array = BitArray::with_capacity(input_vec.len(), 5);
for (i, e) in input_vec.iter().enumerate() {
let char_5bit: u8 = *char_to_5bit.get(e).expect(&format!("Input character '{}' not in alphabet", e));
let char_5bit: u8 =
*char_to_5bit.get(e).unwrap_or_else(|| panic!("Input character '{}' not in alphabet", e));
bit_array.set(i, char_5bit as u64);
}

Expand Down Expand Up @@ -132,8 +133,10 @@ impl ProteinText {
/// * `index` - The index of the character to change.
/// * `value` - The character to fill in as `u8`.
pub fn set(&mut self, index: usize, value: u8) {
let char_5bit: u8 =
*self.char_to_5bit.get(&value).expect(&format!("Input character '{}' not in alphabet", value));
let char_5bit: u8 = *self
.char_to_5bit
.get(&value)
.unwrap_or_else(|| panic!("Input character '{}' not in alphabet", value));
self.bit_array.set(index, char_5bit as u64);
}

Expand Down Expand Up @@ -480,7 +483,7 @@ mod tests {
let mut bit_array = BitArray::with_capacity(input_string.len(), 5);
for (i, c) in input_string.chars().enumerate() {
let char_5bit: u8 =
*char_to_5bit.get(&(c as u8)).expect(&format!("Input character '{}' not in alphabet", c));
*char_to_5bit.get(&(c as u8)).unwrap_or_else(|| panic!("Input character '{}' not in alphabet", c));
bit_array.set(i, char_5bit as u64);
}

Expand Down

0 comments on commit 5094fbf

Please sign in to comment.