Add comment and refactor a bit
parent
1f93e4531f
commit
ddf6b3285c
|
@ -103,17 +103,18 @@ fn main() {
|
||||||
String::from("42")];
|
String::from("42")];
|
||||||
assert_eq!(hex_to_string(&test), "AB");
|
assert_eq!(hex_to_string(&test), "AB");
|
||||||
|
|
||||||
|
// Get command line argument
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let input = &args[1];
|
let input = &args[1];
|
||||||
|
|
||||||
let char_vec: Vec<char> = input.chars().collect();
|
let char_vec: Vec<char> = input.chars().collect();
|
||||||
|
|
||||||
|
// Convert Vec<char> to Vec<String> with 2 hexadecimal chars
|
||||||
|
// ie: ['4','1','4','2'] => ["41", "42"]
|
||||||
let hex_char = &char_vec
|
let hex_char = &char_vec
|
||||||
.chunks(2)
|
.chunks(2)
|
||||||
.map(|chunk| chunk.iter().collect::<String>())
|
.map(|chunk| chunk.iter().collect::<String>())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let input_str = hex_to_string(&hex_char);
|
|
||||||
|
|
||||||
// Convert hex_char : Vec<String> into Vec<u8>
|
// Convert hex_char : Vec<String> into Vec<u8>
|
||||||
// Warning: Panic if not base16
|
// Warning: Panic if not base16
|
||||||
// See this with .map_err if we need to improve :
|
// See this with .map_err if we need to improve :
|
||||||
|
@ -123,6 +124,10 @@ fn main() {
|
||||||
.map(|i| u8::from_str_radix(i, 16).unwrap())
|
.map(|i| u8::from_str_radix(i, 16).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
// Convert Hexadecimal Vec<String> to String
|
||||||
|
// ie: ["41", "42"] => "AB"
|
||||||
|
let input_str = hex_to_string(&hex_char);
|
||||||
|
|
||||||
let output = base64_encode(&hex);
|
let output = base64_encode(&hex);
|
||||||
|
|
||||||
println!("→ Input string is « {} »", input);
|
println!("→ Input string is « {} »", input);
|
||||||
|
|
Loading…
Reference in New Issue