Struct Link

Source
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, 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: 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

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

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());
Source

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());
Source

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);
Source

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());
Source

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);
Source

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

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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

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();
Source

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")
Source

pub fn make_relative(&mut self, base: &str)

Makes this link relative

Trait Implementations§

Source§

fn clone(&self) -> Link

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

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

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

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

fn fields(&self) -> &Map<String, Value>

Gets the fields value. Read more
Source§

fn fields_mut(&mut self) -> &mut Map<String, Value>

Gets a mutable reference to the fields value. Read more
Source§

fn field(&self, key: &str) -> Option<&Value>

Gets the value of a field. Read more
Source§

fn set_field<S: Serialize>( &mut self, key: impl ToString, value: S, ) -> Result<Option<Value>>

Sets the value of a field. Read more
Source§

fn fields_with_prefix<D: DeserializeOwned>(&self, prefix: &str) -> Result<D>

Gets values with a prefix. Read more
Source§

fn set_fields_with_prefix<S: Serialize>( &mut self, prefix: &str, value: S, ) -> Result<()>

Sets values with a prefix. Read more
Source§

fn remove_fields_with_prefix(&mut self, prefix: &str)

Removes values with a prefix. Read more
Source§

fn eq(&self, other: &Link) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromJson for T

Source§

fn from_json_slice(slice: &[u8]) -> Result<Self>

Creates an object from JSON bytes. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToJson for T
where T: Serialize,

Source§

fn to_json_writer(&self, writer: impl Write, pretty: bool) -> Result<()>

Writes a value as JSON. Read more
Source§

fn to_json_vec(&self, pretty: bool) -> Result<Vec<u8>>

Writes a value as JSON bytes. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,