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
52
53
54
55
56
57
58
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
use fastobo_derive_internal::FromStr;
use pest::iterators::Pair;
use crate::ast::StringType;
use crate::error::SyntaxError;
use crate::parser::FromPair;
use crate::syntax::Rule;
#[derive(Clone, Debug, FromStr, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Url(StringType);
impl Url {
pub fn parse(s: &str) -> Result<Self, SyntaxError> {
std::str::FromStr::from_str(s)
}
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl AsRef<str> for Url {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl Display for Url {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
self.0.fmt(f)
}
}
impl<'i> FromPair<'i> for Url {
const RULE: Rule = Rule::Iri;
unsafe fn from_pair_unchecked(pair: Pair<'i, Rule>) -> Result<Self, SyntaxError> {
Ok(Url(StringType::from(pair.as_str())))
}
}