@@ -82,10 +82,11 @@ impl Href {
8282 /// ```
8383 /// use stac::Href;
8484 ///
85- /// let href = Href::from("./a/b.json").absolute(& "/c/d/e.json".into( )).unwrap();
85+ /// let href = Href::from("./a/b.json").into_absolute(Href::from( "/c/d/e.json")).unwrap();
8686 /// assert_eq!(href, "/c/d/a/b.json");
8787 /// ```
88- pub fn absolute ( & self , base : & Href ) -> Result < Href > {
88+ pub fn into_absolute ( & self , base : impl AsRef < Href > ) -> Result < Href > {
89+ let base = base. as_ref ( ) ;
8990 tracing:: debug!( "making href={self} absolute with base={base}" ) ;
9091 match base {
9192 Href :: Url ( url) => url. join ( self . as_str ( ) ) . map ( Href :: Url ) . map_err ( Error :: from) ,
@@ -100,10 +101,11 @@ impl Href {
100101 /// ```
101102 /// use stac::Href;
102103 ///
103- /// let href = Href::from("/a/b/c.json").relative(& "/a/d.json".into( )).unwrap();
104+ /// let href = Href::from("/a/b/c.json").into_relative(Href::from( "/a/d.json")).unwrap();
104105 /// assert_eq!(href, "./b/c.json");
105106 /// ```
106- pub fn relative ( & self , base : & Href ) -> Result < Href > {
107+ pub fn into_relative ( & self , base : impl AsRef < Href > ) -> Result < Href > {
108+ let base = base. as_ref ( ) ;
107109 tracing:: debug!( "making href={self} relative with base={base}" ) ;
108110 match base {
109111 Href :: Url ( base) => match self {
@@ -221,8 +223,13 @@ impl PartialEq<&str> for Href {
221223 }
222224}
223225
226+ impl AsRef < Href > for Href {
227+ fn as_ref ( & self ) -> & Href {
228+ self
229+ }
230+ }
231+
224232fn make_absolute ( href : & str , base : & str ) -> String {
225- // TODO if we make this interface public, make this an impl Option
226233 if href. starts_with ( '/' ) {
227234 href. to_string ( )
228235 } else {
0 commit comments