From a4f4f898b71acf89946ab9ec64bc7dd145f719a5 Mon Sep 17 00:00:00 2001 From: Peter Goodspeed-Niklaus Date: Wed, 18 Nov 2020 12:19:21 +0100 Subject: [PATCH] use byte literals instead of casting char to u8 in exercise examples --- exercises/minesweeper/example.rs | 2 +- exercises/simple-cipher/example.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/minesweeper/example.rs b/exercises/minesweeper/example.rs index 0933909bb..e9e812a17 100644 --- a/exercises/minesweeper/example.rs +++ b/exercises/minesweeper/example.rs @@ -30,7 +30,7 @@ impl Board { if count == 0 { ' ' } else { - (('0' as u8) + count) as char + (b'0' + count) as char } } } diff --git a/exercises/simple-cipher/example.rs b/exercises/simple-cipher/example.rs index ea84d1a26..cb4953f68 100644 --- a/exercises/simple-cipher/example.rs +++ b/exercises/simple-cipher/example.rs @@ -5,7 +5,7 @@ pub fn encode_random(s: &str) -> (String, String) { let mut r = rand::thread_rng(); let mut key = String::new(); for _ in 0..100 { - key.push(char::from('a' as u8 + r.gen_range(0, 26))); + key.push(char::from(b'a' + r.gen_range(0, 26))); } let encoded = encode(&key, s); (key, encoded.unwrap()) @@ -34,8 +34,8 @@ fn shift(key: &str, s: &str, dir: i8) -> Option { } for c in s.chars() { let shift = key_arr[i % key_arr.len()] as i8 - 'a' as i8; - let n = ((c as i8 - 'a' as i8 + dir * shift) % 26 + 26) % 26; - o.push(char::from('a' as u8 + n as u8)); + let n = ((c as i8 - b'a' as i8 + dir * shift) % 26 + 26) % 26; + o.push(char::from(b'a' + n as u8)); i += 1; } Some(o)