Struct stac_api::LinkBuilder
source · pub struct LinkBuilder(_);
Expand description
Build links to endpoints in a STAC API.
Examples
LinkBuilder can be parsed from a string:
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
Note that the root will always have a trailing slash, even if you didn’t provide one:
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
assert_eq!(link_builder.root().href, "http://stac-api-rs.test/api/v1/");
Implementations§
source§impl LinkBuilder
impl LinkBuilder
sourcepub fn root(&self) -> Link
pub fn root(&self) -> Link
Returns a root link.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let root = link_builder.root();
assert_eq!(root.rel, "root");
assert_eq!(root.href, "http://stac-api-rs.test/api/v1/");
sourcepub fn root_self(&self) -> Link
pub fn root_self(&self) -> Link
Returns a root’s self link.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let root = link_builder.root_self();
assert_eq!(root.rel, "self");
assert_eq!(root.href, "http://stac-api-rs.test/api/v1/");
sourcepub fn child_collection(&self, id: &str) -> Result<Link>
pub fn child_collection(&self, id: &str) -> Result<Link>
Returns an child link for a collection.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.child_collection("an-id").unwrap();
assert_eq!(link.rel, "child");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections/an-id");
sourcepub fn collection_parent(&self) -> Link
pub fn collection_parent(&self) -> Link
Returns a parent link for a collection.
This is just the root url.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.collection_parent();
assert_eq!(link.rel, "parent");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/");
sourcepub fn collection_self(&self, id: &str) -> Result<Link>
pub fn collection_self(&self, id: &str) -> Result<Link>
Returns a self link for a collection.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.collection_self("an-id").unwrap();
assert_eq!(link.rel, "self");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections/an-id");
sourcepub fn items<S>(&self, id: &str, parameters: S) -> Result<Link>where
S: Serialize,
pub fn items<S>(&self, id: &str, parameters: S) -> Result<Link>where
S: Serialize,
Returns an items link for a collection.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.items("an-id", ()).unwrap();
assert_eq!(link.rel, "items");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections/an-id/items");
sourcepub fn next_items<S>(&self, id: &str, parameters: S) -> Result<Link>where
S: Serialize,
pub fn next_items<S>(&self, id: &str, parameters: S) -> Result<Link>where
S: Serialize,
Returns a next items link for a collection.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.next_items("an-id", [("foo", "bar")]).unwrap();
assert_eq!(link.rel, "next");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections/an-id/items?foo=bar");
sourcepub fn prev_items<S>(&self, id: &str, parameters: S) -> Result<Link>where
S: Serialize,
pub fn prev_items<S>(&self, id: &str, parameters: S) -> Result<Link>where
S: Serialize,
Returns a prev items link for a collection.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.prev_items("an-id", [("foo", "bar")]).unwrap();
assert_eq!(link.rel, "prev");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections/an-id/items?foo=bar");