encodings.rs

 1use encoding::Encoding;
 2
 3pub enum CharacterEncoding {
 4    Utf8,
 5    Iso8859_1,
 6    Cp865,
 7}
 8
 9pub fn to_utf8<'a>(input: Vec<u8>, encoding: &'a impl encoding::Encoding) -> String {
10    match encoding.decode(&input, encoding::DecoderTrap::Strict) {
11        Ok(v) => return v,
12        Err(_) => panic!(),
13    }
14}
15
16pub fn to<'a>(input: String, target: &'a impl encoding::Encoding) -> Vec<u8> {
17    match target.encode(&input, encoding::EncoderTrap::Strict) {
18        Ok(v) => v,
19        Err(_) => panic!(),
20    }
21}