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::{display::UriRefDisplay, Authority, ParseUriError, Resource, Scheme, Uri};
use shared_bytes::SharedStr;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct UriRef {
pub scheme: Option<Scheme>,
pub authority: Option<Authority>,
pub resource: Resource,
#[doc(hidden)]
pub __private: (),
}
impl UriRef {
pub fn new() -> Self {
Default::default()
}
pub fn parse(s: SharedStr) -> Result<Self, ParseUriError> {
crate::parse::parse_uri_ref(s)
}
pub fn into_uri_with_default_scheme<F>(self, scheme: F) -> Uri
where
F: FnOnce() -> Scheme,
{
Uri {
scheme: self.scheme.unwrap_or_else(scheme),
authority: self.authority,
resource: self.resource,
__private: (),
}
}
}
impl From<Uri> for UriRef {
fn from(uri: Uri) -> Self {
Self {
scheme: Some(uri.scheme),
authority: uri.authority,
resource: uri.resource,
__private: (),
}
}
}
impl fmt::Display for UriRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", UriRefDisplay::from(self))
}
}