pub struct Link {
pub href: Href,
pub rel: String,
pub type: Option<String>,
pub title: Option<String>,
pub method: Option<String>,
pub headers: Option<Map<String, Value>>,
pub body: Option<Map<String, Value>>,
pub merge: Option<bool>,
pub additional_fields: Map<String, Value>,
}Expand description
This object describes a relationship with another entity.
Data providers are advised to be liberal with the links section, to describe
things like the Catalog`` an Itemis in, relatedItems, parent or child Item`s (modeled in different ways, like an
‘acquisition’ or derived data). It is allowed to add additional fields such
as a title and type.
This link structure includes a few fields from the STAC API specification. Generally we keep STAC API structures in the stac-api crate, but in this case it was simpler to include these attributes in the base Link rather to create a new one.
Fields§
§href: HrefThe actual link in the format of an URL.
Relative and absolute links are both allowed.
rel: StringRelationship between the current document and the linked document.
See the chapter on “Relation types” in the STAC spec for more information.
type: Option<String>Media type of the referenced entity.
title: Option<String>A human readable title to be used in rendered displays of the link.
method: Option<String>The HTTP method of the request, usually GET or POST. Defaults to GET.
From the STAC API spec.
headers: Option<Map<String, Value>>A dictionary of header values that must be included in the next request
From the STAC API spec.
body: Option<Map<String, Value>>A JSON object containing fields/values that must be included in the body of the next request.
From the STAC API spec.
merge: Option<bool>If true, the headers/body fields in the next link must be merged into the original request and be sent combined in the next request. Defaults to false
From the STAC API spec.
additional_fields: Map<String, Value>Additional fields on the link.
Implementations§
Source§impl Link
impl Link
Sourcepub fn new(href: impl Into<Href>, rel: impl ToString) -> Link
pub fn new(href: impl Into<Href>, rel: impl ToString) -> Link
Creates a new link with the provided href and rel type.
§Examples
let link = Link::new("an-href", "a-rel");
assert_eq!(link.href, "an-href");
assert_eq!(link.rel, "a-rel");Sourcepub fn json(self) -> Link
pub fn json(self) -> Link
Sets this link’s media type to JSON.
§Examples
use stac::Link;
let link = Link::new("a/href", "rel-type").json();
assert_eq!(link.r#type.unwrap(), ::mime::APPLICATION_JSON.as_ref());Sourcepub fn is_json(&self) -> bool
pub fn is_json(&self) -> bool
Returns true if this link’s media type is JSON.
§Examples
use stac::Link;
let link = Link::new("a/href", "rel-type").json();
assert!(link.is_json());Sourcepub fn geojson(self) -> Link
pub fn geojson(self) -> Link
Sets this link’s media type to GeoJSON.
§Examples
use stac::{Link, mime};
let link = Link::new("a/href", "rel-type").geojson();
assert_eq!(link.r#type.unwrap(), mime::GEOJSON);Sourcepub fn is_geojson(&self) -> bool
pub fn is_geojson(&self) -> bool
Returns true if this link’s media type is GeoJSON.
§Examples
use stac::Link;
let link = Link::new("a/href", "rel-type").geojson();
assert!(link.is_geojson());Sourcepub fn type(self, type: impl Into<Option<String>>) -> Link
pub fn type(self, type: impl Into<Option<String>>) -> Link
Sets this link’s media type.
§Examples
use stac::{Link, mime};
let link = Link::new("a/href", "rel-type").r#type(mime::GEOJSON.to_string());
assert_eq!(link.r#type.unwrap(), mime::GEOJSON);Sourcepub fn title(self, title: impl Into<Option<String>>) -> Link
pub fn title(self, title: impl Into<Option<String>>) -> Link
Sets this link’s title.
§Examples
use stac::Link;
let link = Link::new("a/href", "rel-type").title("a title".to_string());
assert_eq!(link.title.unwrap(), "a title");Sourcepub fn root(href: impl Into<Href>) -> Link
pub fn root(href: impl Into<Href>) -> Link
Creates a new root link with JSON media type.
§Examples
let link = Link::root("an-href");
assert!(link.is_root());
assert_eq!(link.r#type.as_ref().unwrap(), ::mime::APPLICATION_JSON.as_ref());Sourcepub fn self_(href: impl Into<Href>) -> Link
pub fn self_(href: impl Into<Href>) -> Link
Creates a new self link with JSON media type.
§Examples
let link = Link::self_("an-href");
assert!(link.is_self());
assert_eq!(link.r#type.as_ref().unwrap(), ::mime::APPLICATION_JSON.as_ref());Sourcepub fn child(href: impl Into<Href>) -> Link
pub fn child(href: impl Into<Href>) -> Link
Creates a new child link with JSON media type.
§Examples
let link = Link::child("an-href");
assert!(link.is_child());
assert_eq!(link.r#type.as_ref().unwrap(), ::mime::APPLICATION_JSON.as_ref());Sourcepub fn item(href: impl Into<Href>) -> Link
pub fn item(href: impl Into<Href>) -> Link
Creates a new item link with JSON media type.
§Examples
let link = Link::item("an-href");
assert!(link.is_item());
assert_eq!(link.r#type.as_ref().unwrap(), ::mime::APPLICATION_JSON.as_ref());Sourcepub fn parent(href: impl Into<Href>) -> Link
pub fn parent(href: impl Into<Href>) -> Link
Creates a new parent link with JSON media type.
§Examples
let link = Link::parent("an-href");
assert!(link.is_parent());
assert_eq!(link.r#type.as_ref().unwrap(), ::mime::APPLICATION_JSON.as_ref());Sourcepub fn collection(href: impl Into<Href>) -> Link
pub fn collection(href: impl Into<Href>) -> Link
Creates a new collection link with JSON media type.
§Examples
let link = Link::collection("an-href");
assert!(link.is_collection());
assert_eq!(link.r#type.as_ref().unwrap(), ::mime::APPLICATION_JSON.as_ref());Sourcepub fn is_item(&self) -> bool
pub fn is_item(&self) -> bool
Returns true if this link’s rel is "item".
§Examples
let link = Link::new("an-href", "item");
assert!(link.is_item());
let link = Link::new("an-href", "not-an-item");
assert!(!link.is_item());Sourcepub fn is_child(&self) -> bool
pub fn is_child(&self) -> bool
Returns true if this link’s rel is "child".
§Examples
let link = Link::new("an-href", "child");
assert!(link.is_child());
let link = Link::new("an-href", "not-a-child");
assert!(!link.is_child());Sourcepub fn is_parent(&self) -> bool
pub fn is_parent(&self) -> bool
Returns true if this link’s rel is "parent".
§Examples
let link = Link::new("an-href", "parent");
assert!(link.is_parent());
let link = Link::new("an-href", "not-a-parent");
assert!(!link.is_parent());Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Returns true if this link’s rel is "root".
§Examples
let link = Link::new("an-href", "root");
assert!(link.is_root());
let link = Link::new("an-href", "not-a-root");
assert!(!link.is_root());Sourcepub fn is_self(&self) -> bool
pub fn is_self(&self) -> bool
Returns true if this link’s rel is "self".
§Examples
let link = Link::new("an-href", "self");
assert!(link.is_self());
let link = Link::new("an-href", "not-a-self");
assert!(!link.is_self());Sourcepub fn is_collection(&self) -> bool
pub fn is_collection(&self) -> bool
Returns true if this link’s rel is "collection".
§Examples
let link = Link::new("an-href", "collection");
assert!(link.is_collection());
let link = Link::new("an-href", "not-a-collection");
assert!(!link.is_collection());Sourcepub fn is_structural(&self) -> bool
pub fn is_structural(&self) -> bool
Returns true if this link is structural (i.e. not child, parent, item, root, or self).
Also includes some API structural link types such as “data”, “conformance”, “items”, and “search”.
§Examples
let link = Link::new("an-href", "self");
assert!(link.is_structural());
let link = Link::new("an-href", "child");
assert!(link.is_structural());
let link = Link::new("an-href", "not-a-root");
assert!(!link.is_structural());Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
Returns true if this link’s href is an absolute path or url.
§Examples
use stac::Link;
assert!(Link::new("/a/local/path/item.json", "rel").is_absolute());
assert!(Link::new("http://stac-rs.test/item.json", "rel").is_absolute());
assert!(!Link::new("./not/an/absolute/path", "rel").is_absolute());Sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
Returns true if this link’s href is a relative path.
§Examples
use stac::Link;
assert!(!Link::new("/a/local/path/item.json", "rel").is_relative());
assert!(!Link::new("http://stac-rs.test/item.json", "rel").is_relative());
assert!(Link::new("./not/an/absolute/path", "rel").is_relative());Sourcepub fn method(self, method: impl ToString) -> Link
pub fn method(self, method: impl ToString) -> Link
Sets the method attribute on this link.
§Examples
use stac::Link;
let link = Link::new("href", "rel").method("GET");Sourcepub fn body<T: Serialize>(self, body: T) -> Result<Link>
pub fn body<T: Serialize>(self, body: T) -> Result<Link>
Sets the body attribute on this link.
§Examples
use stac::Link;
use serde_json::json;
let link = Link::new("href", "rel").body(json!({"foo": "bar"})).unwrap();Sourcepub fn make_absolute(&mut self, base: &Href) -> Result<()>
pub fn make_absolute(&mut self, base: &Href) -> Result<()>
Makes this link absolute.
If the href is relative, use the passed in value as a base.
§Examples
use stac::Link;
let mut link = Link::new("./b/item.json", "rel");
link.make_absolute(&"/a/base/catalog.json".into()).unwrap();
assert_eq!(link.href, "/a/base/b/item.json")Sourcepub fn make_relative(&mut self, base: &Href) -> Result<()>
pub fn make_relative(&mut self, base: &Href) -> Result<()>
Makes this link relative