use std::ops::RangeInclusive;
pub trait Charset {
fn get_charset(&self) -> Vec<char>;
}
pub struct Alphanumeric();
impl Charset for Alphanumeric {
fn get_charset(&self) -> Vec<char>
{
const CHARCODE_RANGES: [RangeInclusive<u8>; 3] = [
0x30..=0x39,
0x41..=0x5a,
0x61..=0x7a
];
let mut outvec: Vec<char> = Vec::with_capacity(62);
for charcode_range in CHARCODE_RANGES {
for charcode in charcode_range {
outvec.push(charcode as char);
}
}
outvec
}
}
pub struct PrintableAscii();
impl Charset for PrintableAscii {
fn get_charset(&self) -> Vec<char>
{
let mut outvec: Vec<char> = Vec::with_capacity(93);
for charcode in 0x21..=0x7E_u8 {
outvec.push(charcode as char);
}
outvec
}
}
pub struct AsciiAndSymbols();
impl Charset for AsciiAndSymbols {
fn get_charset(&self) -> Vec<char>
{
let mut outvec = PrintableAscii().get_charset();
const CHARCODE_RANGES: [RangeInclusive<u32>; 3] = [
0x2100..=0x2138, 0x213A..=0x214F,
0x2A00..=0x2AFF];
for charcode_range in CHARCODE_RANGES {
for charcode in charcode_range {
outvec.push(char::from_u32(charcode).expect("tried to add invalid char to AsciiAndSymbols"));
}
}
outvec
}
}