Skip to content

Commit

Permalink
Add missing character to error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pverscha committed Sep 19, 2024
1 parent 757426e commit e3cc70f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions text-compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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("Input character not in alphabet");
let char_5bit: u8 = *char_to_5bit.get(&(c as u8)).expect(&format!("Input character '{}' not in alphabet", c));
bit_array.set(i, char_5bit as u64);
}

Expand All @@ -79,7 +79,7 @@ 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("Input character not in alphabet");
let char_5bit: u8 = *char_to_5bit.get(&(e as u8)).expect(&format!("Input character '{}' not in alphabet", e));

Check failure on line 82 in text-compression/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check + test

casting `&u8` as `u8` is invalid
bit_array.set(i, char_5bit as u64);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ 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("Input character not in alphabet");
let char_5bit: u8 = *self.char_to_5bit.get(&value).expect(&format!("Input character '{}' not in alphabet", value));
self.bit_array.set(index, char_5bit as u64);
}

Expand Down Expand Up @@ -477,7 +477,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("Input character not in alphabet");
let char_5bit: u8 = *char_to_5bit.get(&(c as u8)).expect(&format!("Input character '{}' not in alphabet", c));
bit_array.set(i, char_5bit as u64);
}

Expand Down

0 comments on commit e3cc70f

Please sign in to comment.