Skip to content

Commit 104961b

Browse files
authored
refactor!: remove Href (#760)
It was an abstraction we didn't need, it turns out.
1 parent e715de6 commit 104961b

File tree

23 files changed

+169
-359
lines changed

23 files changed

+169
-359
lines changed

crates/api/src/collections.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use serde_json::{Map, Value};
3-
use stac::{Collection, Href, Link};
3+
use stac::{Collection, Link};
44
use stac_derive::{Links, SelfHref};
55

66
/// Object containing an array of collections and an array of links.
@@ -17,7 +17,7 @@ pub struct Collections {
1717
pub additional_fields: Map<String, Value>,
1818

1919
#[serde(skip)]
20-
self_href: Option<Href>,
20+
self_href: Option<String>,
2121
}
2222

2323
impl From<Vec<Collection>> for Collections {

crates/api/src/item_collection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{Item, Result};
22
use serde::{Deserialize, Deserializer, Serialize};
33
use serde_json::{Map, Value};
4-
use stac::{Href, Link};
4+
use stac::Link;
55
use stac_derive::{Links, SelfHref};
66

77
const ITEM_COLLECTION_TYPE: &str = "FeatureCollection";
@@ -95,7 +95,7 @@ pub struct ItemCollection {
9595
pub last: Option<Map<String, Value>>,
9696

9797
#[serde(skip)]
98-
self_href: Option<Href>,
98+
self_href: Option<String>,
9999
}
100100

101101
/// The search-related metadata for the [ItemCollection].

crates/cli/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use async_stream::try_stream;
77
use clap::{Parser, Subcommand};
88
use futures_core::TryStream;
99
use futures_util::{TryStreamExt, pin_mut};
10-
use stac::{Assets, Collection, Href, Item, Links, Migrate, SelfHref, geoparquet::Compression};
10+
use stac::{Assets, Collection, Item, Links, Migrate, SelfHref, geoparquet::Compression};
1111
use stac_api::{GetItems, GetSearch, Search};
1212
use stac_io::{Format, StacStore, Validate};
1313
use stac_server::Backend;
@@ -527,7 +527,7 @@ impl Rustac {
527527
let href = href.and_then(|s| if s == "-" { None } else { Some(s) });
528528
let format = self.input_format(href);
529529
if let Some(href) = href {
530-
let (store, path) = stac_io::parse_href_opts(Href::from(href), self.opts())?;
530+
let (store, path) = stac_io::parse_href_opts(href, self.opts())?;
531531
let value: stac::Value = store.get_format(path, format).await?;
532532
Ok(value)
533533
} else {
@@ -542,7 +542,7 @@ impl Rustac {
542542
let href = href.and_then(|s| if s == "-" { None } else { Some(s) });
543543
let format = self.output_format(href);
544544
if let Some(href) = href {
545-
let (store, path) = stac_io::parse_href_opts(Href::from(href), self.opts())?;
545+
let (store, path) = stac_io::parse_href_opts(href, self.opts())?;
546546
let _ = match value {
547547
Value::Json(json) => store.put_format(path, json, format).await?,
548548
Value::Stac(stac) => store.put_format(path, stac, format).await?,
@@ -742,7 +742,7 @@ async fn crawl(value: stac::Value, store: StacStore) -> impl TryStream<Item = Re
742742
.cloned()
743743
{
744744
let store = store.clone();
745-
let url = Url::try_from(link.href)?;
745+
let url = Url::parse(&link.href)?;
746746
join_set.spawn(async move {
747747
let value: stac::Value = store.get(url.path()).await?;
748748
Ok(value)
@@ -754,15 +754,17 @@ async fn crawl(value: stac::Value, store: StacStore) -> impl TryStream<Item = Re
754754
}
755755
}
756756
Item(mut item) => {
757-
if let Some(self_href) = item.self_href().cloned() {
758-
item.make_assets_absolute(self_href)?;
757+
if let Some(self_href) = item.self_href() {
758+
let self_href= self_href.to_string();
759+
item.make_assets_absolute(&self_href)?;
759760
}
760761
yield item;
761762
}
762763
ItemCollection(item_collection) => {
763764
for mut item in item_collection.items {
764-
if let Some(self_href) = item.self_href().cloned() {
765-
item.make_assets_absolute(self_href)?;
765+
if let Some(self_href) = item.self_href() {
766+
let self_href = self_href.to_string();
767+
item.make_assets_absolute(&self_href)?;
766768
}
767769
yield item;
768770
}

crates/core/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2121

2222
- Default to snappy compression for geoparquet ([#673](https://github.com/stac-utils/rustac/pull/673))
2323
- Ensure geoparquet->json provides valid datetime strings (UTC) ([#711](https://github.com/stac-utils/rustac/pull/711)])
24-
- Some `Href` method names ([#747](https://github.com/stac-utils/rustac/pull/747))
25-
- Use `Href` for `Asset.href` 🙈 ([#752](https://github.com/stac-utils/rustac/pull/752))
2624
- `href::make_absolute` is now public ([#757](https://github.com/stac-utils/rustac/pull/757))
2725

2826
### Fixed
@@ -32,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3230
### Removed
3331

3432
- IO (moved to **stac-io**) ([#739](https://github.com/stac-utils/rustac/pull/739))
33+
- `Href` ([#760](https://github.com/stac-utils/rustac/pull/760))
3534

3635
## [0.12.0] - 2025-01-31
3736

crates/core/src/asset.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Band, DataType, Href, Result, Statistics};
1+
use crate::{Band, DataType, Result, Statistics};
22
use indexmap::IndexMap;
33
use serde::{Deserialize, Serialize};
44
use serde_json::{Map, Value};
@@ -10,7 +10,7 @@ pub struct Asset {
1010
/// URI to the asset object.
1111
///
1212
/// Relative and absolute URIs are both allowed.
13-
pub href: Href,
13+
pub href: String,
1414

1515
/// The displayed title for clients and users.
1616
#[serde(skip_serializing_if = "Option::is_none")]
@@ -114,9 +114,9 @@ pub trait Assets {
114114
fn assets_mut(&mut self) -> &mut IndexMap<String, Asset>;
115115

116116
/// Makes all asset hrefs absolute.
117-
fn make_assets_absolute(&mut self, base: impl AsRef<Href>) -> Result<()> {
117+
fn make_assets_absolute(&mut self, base: &str) -> Result<()> {
118118
for asset in self.assets_mut().values_mut() {
119-
asset.href = asset.href.into_absolute(&base)?;
119+
asset.href = crate::href::make_absolute(&asset.href, base)?.into();
120120
}
121121
Ok(())
122122
}
@@ -132,9 +132,9 @@ impl Asset {
132132
/// let asset = Asset::new("an-href");
133133
/// assert_eq!(asset.href, "an-href");
134134
/// ```
135-
pub fn new(href: impl Into<Href>) -> Asset {
135+
pub fn new(href: impl ToString) -> Asset {
136136
Asset {
137-
href: href.into(),
137+
href: href.to_string(),
138138
title: None,
139139
description: None,
140140
r#type: None,
@@ -183,7 +183,7 @@ impl<'a> From<&'a str> for Asset {
183183
#[cfg(test)]
184184
mod tests {
185185
use super::{Asset, Assets};
186-
use crate::{Href, Item};
186+
use crate::Item;
187187

188188
#[test]
189189
fn new() {
@@ -210,8 +210,7 @@ mod tests {
210210
let asset = Asset::new("an-href");
211211
let mut item = Item::new("an-item");
212212
let _ = item.assets.insert("data".into(), asset);
213-
item.make_assets_absolute(Href::from("http://rustac.test"))
214-
.unwrap();
213+
item.make_assets_absolute("http://rustac.test").unwrap();
215214
assert_eq!(item.assets["data"].href, "http://rustac.test/an-href");
216215
}
217216
}

crates/core/src/catalog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Error, Href, Link, Result, STAC_VERSION, Version};
1+
use crate::{Error, Link, Result, STAC_VERSION, Version};
22
use serde::{Deserialize, Deserializer, Serialize};
33
use serde_json::{Map, Value};
44
use stac_derive::{Fields, Links, Migrate, SelfHref};
@@ -77,7 +77,7 @@ pub struct Catalog {
7777
pub additional_fields: Map<String, Value>,
7878

7979
#[serde(skip)]
80-
self_href: Option<Href>,
80+
self_href: Option<String>,
8181
}
8282

8383
impl Catalog {

crates/core/src/collection.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
Asset, Assets, Bbox, Error, Href, Item, ItemAsset, Link, Links, Migrate, Result, STAC_VERSION,
2+
Asset, Assets, Bbox, Error, Item, ItemAsset, Link, Links, Migrate, Result, STAC_VERSION,
33
SelfHref, Version,
44
};
55
use chrono::{DateTime, Utc};
@@ -119,7 +119,7 @@ pub struct Collection {
119119
pub additional_fields: Map<String, Value>,
120120

121121
#[serde(skip)]
122-
self_href: Option<Href>,
122+
self_href: Option<String>,
123123
}
124124

125125
/// This object provides information about a provider.
@@ -246,7 +246,7 @@ impl Collection {
246246

247247
/// Creates a new collection with its extents set to match the item's.
248248
///
249-
/// Also, adds an `item` link if the item has a [Href] or a `item`.
249+
/// Also, adds an `item` link if the item has a href or a `item`.
250250
///
251251
/// # Examples
252252
///
@@ -276,8 +276,11 @@ impl Collection {
276276
}
277277

278278
fn maybe_add_item_link(&mut self, item: &Item) -> Option<&Link> {
279-
if let Some(href) = item.self_href().or(item.self_link().map(|link| &link.href)) {
280-
self.links.push(Link::item(href.clone()));
279+
if let Some(href) = item
280+
.self_href()
281+
.or(item.self_link().map(|link| link.href.as_str()))
282+
{
283+
self.links.push(Link::item(href));
281284
self.links.last()
282285
} else {
283286
None
@@ -289,7 +292,7 @@ impl Collection {
289292
/// This method does a couple of things:
290293
///
291294
/// 1. Updates this collection's extents to contain the item's spatial and temporal bounds
292-
/// 2. If the item has a [Href] or a `self` link, adds a `item` link
295+
/// 2. If the item has a href or a `self` link, adds a `item` link
293296
///
294297
/// Note that collections are created, by default, with global bounds and no
295298
/// temporal extent, so you'll want to set those (e.g. with

0 commit comments

Comments
 (0)