@@ -25,9 +25,14 @@ impl Href {
25
25
/// use stac::Href;
26
26
/// let href = Href::new("data", None).unwrap();
27
27
/// assert!(href.to_str().starts_with("/"));
28
- /// assert_eq!(Href::new("a/path", Some("http://example.com")).unwrap().to_str(), "http://example.com/a/path");
28
+ /// assert_eq!(
29
+ /// Href::new("a/path", "http://example.com").unwrap().to_str(),
30
+ /// "http://example.com/a/path"
31
+ /// );
29
32
/// ```
30
- pub fn new ( href : & str , base : Option < & str > ) -> Result < Href , Error > {
33
+ #[ allow( single_use_lifetimes) ] // https://github.com/rust-lang/rust/issues/60554
34
+ pub fn new < ' a , T : Into < Option < & ' a str > > > ( href : & str , base : T ) -> Result < Href , Error > {
35
+ let base = base. into ( ) ;
31
36
if let Ok ( url) = Url :: parse ( href) {
32
37
return Ok ( Href :: Url ( url) ) ;
33
38
}
@@ -62,7 +67,9 @@ impl Href {
62
67
/// ```
63
68
/// use stac::Href;
64
69
/// let href = Href::new("data/catalog.json", None).unwrap();
65
- /// println!("{}", href.to_str());
70
+ /// assert!(href.as_path().is_some());
71
+ /// let href = Href::new("./catalog.json", "http://example.com/stac").unwrap();
72
+ /// assert!(href.as_path().is_none());
66
73
/// ```
67
74
pub fn to_str ( & self ) -> & str {
68
75
match self {
@@ -80,7 +87,7 @@ mod tests {
80
87
fn catalog_base ( ) {
81
88
let href = Href :: new (
82
89
"./extensions-collection/collection.json" ,
83
- Some ( "data/catalog.json" ) ,
90
+ "data/catalog.json" ,
84
91
)
85
92
. unwrap ( ) ;
86
93
assert ! ( href
0 commit comments