Links

Trait Links 

Source
pub trait Links: SelfHref {
Show 13 methods // Required methods fn links(&self) -> &[Link]; fn links_mut(&mut self) -> &mut Vec<Link>; // Provided methods fn link(&self, rel: &str) -> Option<&Link> { ... } fn set_link(&mut self, link: Link) { ... } fn root_link(&self) -> Option<&Link> { ... } fn self_link(&self) -> Option<&Link> { ... } fn parent_link(&self) -> Option<&Link> { ... } fn iter_child_links(&self) -> Box<dyn Iterator<Item = &Link> + '_> { ... } fn iter_item_links(&self) -> Box<dyn Iterator<Item = &Link> + '_> { ... } fn make_links_absolute(&mut self) -> Result<()> { ... } fn make_links_relative(&mut self) -> Result<()> { ... } fn remove_relative_links(&mut self) { ... } fn remove_structural_links(&mut self) { ... }
}
Expand description

Implemented by any object that has links.

Required Methods§

Returns a reference to this object’s links.

§Examples

Value implements Links:

use stac::Links;
let item: stac::Item = stac::read("examples/simple-item.json").unwrap();
let links = item.links();

Returns a mutable reference to this object’s links.

§Examples

`Value`` implements Links:

use stac::Links;
let mut item: stac::Item = stac::read("examples/simple-item.json").unwrap();
let links = item.links_mut();
links.clear();

Provided Methods§

Returns the first link with the given rel type.

§Examples
use stac::Links;
let item: stac::Item = stac::read("examples/simple-item.json").unwrap();
let link = item.link("root").unwrap();

Sets a link of the given rel type.

This will remove all other links of that rel type, so should only be used for e.g. “root”, not e.g. “child”.

§Examples
use stac::{Links, Link};
let mut item: stac::Item = stac::read("examples/simple-item.json").unwrap();
item.set_link(Link::root("a/href"));

Returns this object’s root link.

This is the first link with a rel=“root”.

§Examples
use stac::Links;
let item: stac::Item = stac::read("examples/simple-item.json").unwrap();
let link = item.root_link().unwrap();

Returns this object’s self link.

This is the first link with a rel=“self”.

§Examples
use stac::Links;
let item: stac::Item = stac::read("examples/simple-item.json").unwrap();
let link = item.root_link().unwrap();

Returns this object’s parent link.

This is the first link with a rel=“parent”.

§Examples
use stac::Links;
let item: stac::Item = stac::read("examples/simple-item.json").unwrap();
let link = item.parent_link().unwrap();

Returns an iterator over this object’s child links.

§Examples
use stac::Links;
let collection: stac::Collection = stac::read("examples/collection.json").unwrap();
let links: Vec<_> = collection.iter_child_links().collect();

Returns an iterator over this object’s item links.

§Examples
use stac::Links;
let collection: stac::Collection = stac::read("examples/collection.json").unwrap();
let links: Vec<_> = collection.iter_item_links().collect();

Makes all relative links absolute with respect to this object’s self href.

Makes all links relative with respect to this object’s self href.

Removes all relative links.

This can be useful e.g. if you’re relocating a STAC object, but it doesn’t have a href, so the relative links wouldn’t make any sense.

§Examples
use stac::{Catalog, Links, Link};
let mut catalog = Catalog::new("an-id", "a description");
catalog.links.push(Link::new("./child.json", "child"));
catalog.remove_relative_links();
assert!(catalog.links.is_empty());

Removes all structural links.

Useful if you’re, e.g., going to re-populate the structural links as a part of serving items with a STAC API.

§Examples
use stac::{Catalog, Links, Link};
let mut catalog = Catalog::new("an-id", "a description");
catalog.links.push(Link::self_("http://stac.test/catalog.json"));
catalog.remove_structural_links();
assert!(catalog.links.is_empty());

Implementors§