1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::collections::HashMap;
pub trait Encode {
type Output;
fn encode(&self, src: &[u8]) -> Self::Output;
}
pub trait Decode {
type Output;
fn decode(&self, src: String) -> Self::Output;
}
pub fn generate_alpha_map(alphabet: &[u8]) -> HashMap<char, usize> {
let mut map: HashMap<char, usize> = HashMap::new();
let lens = alphabet.len();
let mut i = 0;
while i < lens {
let x = alphabet[i] as char;
map.insert(x, i);
i += 1;
}
map
}