pub struct Link {
pub href: String,
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, related
Items, 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: String
The actual link in the format of an URL.
Relative and absolute links are both allowed.
rel: String
Relationship 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 ToString, rel: impl ToString) -> Link
pub fn new(href: impl ToString, 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 ToString) -> Link
pub fn root(href: impl ToString) -> 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 ToString) -> Link
pub fn self_(href: impl ToString) -> 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 ToString) -> Link
pub fn child(href: impl ToString) -> 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 ToString) -> Link
pub fn item(href: impl ToString) -> 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 ToString) -> Link
pub fn parent(href: impl ToString) -> 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 ToString) -> Link
pub fn collection(href: impl ToString) -> 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://rustac.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://rustac.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: &str) -> Result<()>
pub fn make_absolute(&mut self, base: &str) -> 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").unwrap();
assert_eq!(link.href, "/a/base/b/item.json")
Sourcepub fn make_relative(&mut self, base: &str)
pub fn make_relative(&mut self, base: &str)
Makes this link relative
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Link
impl<'de> Deserialize<'de> for Link
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Fields for Link
impl Fields for Link
Source§fn fields_mut(&mut self) -> &mut Map<String, Value>
fn fields_mut(&mut self) -> &mut Map<String, Value>
Source§fn set_field<S: Serialize>(
&mut self,
key: impl ToString,
value: S,
) -> Result<Option<Value>>
fn set_field<S: Serialize>( &mut self, key: impl ToString, value: S, ) -> Result<Option<Value>>
Source§fn fields_with_prefix<D: DeserializeOwned>(&self, prefix: &str) -> Result<D>
fn fields_with_prefix<D: DeserializeOwned>(&self, prefix: &str) -> Result<D>
Source§fn set_fields_with_prefix<S: Serialize>(
&mut self,
prefix: &str,
value: S,
) -> Result<()>
fn set_fields_with_prefix<S: Serialize>( &mut self, prefix: &str, value: S, ) -> Result<()>
Source§fn remove_fields_with_prefix(&mut self, prefix: &str)
fn remove_fields_with_prefix(&mut self, prefix: &str)
impl StructuralPartialEq for Link
Auto Trait Implementations§
impl Freeze for Link
impl RefUnwindSafe for Link
impl Send for Link
impl Sync for Link
impl Unpin for Link
impl UnwindSafe for Link
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromJson for Twhere
T: DeserializeOwned,
impl<T> FromJson for Twhere
T: DeserializeOwned,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more