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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::base64;
use crate::error::{InvalidSeperator, SeperatorNotFound};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Seperator(pub(crate) char);
impl Seperator {
pub fn new(seperator: char) -> Result<Self, InvalidSeperator> {
if base64::in_alphabet(seperator) {
Err(InvalidSeperator(seperator))
} else {
Ok(Self(seperator))
}
}
#[inline(always)]
pub fn split<'a>(&self, value: &'a str) -> Result<(&'a str, &'a str), SeperatorNotFound> {
let mut iterator = value.rsplitn(2, self.0);
let second = iterator.next().unwrap();
let first = match iterator.next() {
None => return Err(SeperatorNotFound { seperator: *self }),
Some(val) => val,
};
Ok((first, second))
}
}
impl Default for Seperator {
fn default() -> Self {
Self('.')
}
}