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
use serde::{Deserialize, Serialize};
use std::fmt;
use nom::{
IResult,
branch::alt,
combinator::map,
error::ParseError,
bytes::complete::tag_no_case
};
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub enum UriSchema {
Sip,
Sips,
}
impl fmt::Display for UriSchema {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
UriSchema::Sip => write!(f, "sip"),
UriSchema::Sips => write!(f, "sips"),
}
}
}
pub fn parse_schema<'a, E: ParseError<&'a [u8]>>(input: &'a [u8]) -> IResult<&'a [u8], UriSchema, E> {
alt::<_, _, E, _>((
map(tag_no_case::<_, _, E>("sip"), |_| UriSchema::Sip),
map(tag_no_case::<_, _, E>("sips"), |_| UriSchema::Sips)
))(input)
}