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_to_self(&self) -> Link
pub fn root_to_self(&self) -> Link
Returns a root’s self link.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.root_to_self();
assert_eq!(link.rel, "self");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/");
sourcepub fn collections_to_self(&self) -> Link
pub fn collections_to_self(&self) -> Link
Returns the collections’ self link.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.collections_to_self();
assert_eq!(link.rel, "self");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections");
sourcepub fn service_desc(&self) -> Link
pub fn service_desc(&self) -> Link
Returns a service-desc link.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.service_desc();
assert_eq!(link.rel, "service-desc");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/api");
sourcepub fn conformance(&self) -> Link
pub fn conformance(&self) -> Link
Returns a conformance link.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.conformance();
assert_eq!(link.rel, "conformance");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/conformance");
sourcepub fn collections(&self) -> Link
pub fn collections(&self) -> Link
Returns a collections link.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.collections();
assert_eq!(link.rel, "data");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections");
sourcepub fn root_to_collection(&self, id: &str) -> Result<Link, ParseError>
pub fn root_to_collection(&self, id: &str) -> Result<Link, ParseError>
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.root_to_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_to_parent(&self) -> Link
pub fn collection_to_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_to_parent();
assert_eq!(link.rel, "parent");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/");
sourcepub fn collection_to_self(&self, id: &str) -> Result<Link, ParseError>
pub fn collection_to_self(&self, id: &str) -> Result<Link, ParseError>
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_to_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 next_items<S>(&self, id: &str, parameters: S) -> Result<Link, Error>where
S: Serialize,
pub fn next_items<S>(&self, id: &str, parameters: S) -> Result<Link, Error>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, Error>where
S: Serialize,
pub fn prev_items<S>(&self, id: &str, parameters: S) -> Result<Link, Error>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");
sourcepub fn collection_to_items(&self, id: &str) -> Result<Link, Error>
pub fn collection_to_items(&self, id: &str) -> Result<Link, Error>
Returns a link from a collection to its items.
Examples
let link_builder: LinkBuilder = "http://stac-api-rs.test/api/v1".parse().unwrap();
let link = link_builder.collection_to_items("an-id").unwrap();
assert_eq!(link.rel, "items");
assert_eq!(link.href, "http://stac-api-rs.test/api/v1/collections/an-id/items");
Trait Implementations§
source§impl Clone for LinkBuilder
impl Clone for LinkBuilder
source§fn clone(&self) -> LinkBuilder
fn clone(&self) -> LinkBuilder
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more