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

source

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/");
source

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/");
source

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");
source

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");
source

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");
source

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");
source

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");
source

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/");
source

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");
source

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");
source

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");
source

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

source§

fn clone(&self) -> LinkBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LinkBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for LinkBuilder

§

type Err = ParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.