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§
Provided Methods§
Sourcefn link(&self, rel: &str) -> Option<&Link>
fn link(&self, rel: &str) -> Option<&Link>
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();Sourcefn set_link(&mut self, link: Link)
fn set_link(&mut self, link: Link)
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"));Sourcefn root_link(&self) -> Option<&Link>
fn root_link(&self) -> Option<&Link>
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();Sourcefn self_link(&self) -> Option<&Link>
fn self_link(&self) -> Option<&Link>
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();Sourcefn parent_link(&self) -> Option<&Link>
fn parent_link(&self) -> Option<&Link>
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();Sourcefn iter_child_links(&self) -> Box<dyn Iterator<Item = &Link> + '_>
fn iter_child_links(&self) -> Box<dyn Iterator<Item = &Link> + '_>
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();Sourcefn iter_item_links(&self) -> Box<dyn Iterator<Item = &Link> + '_>
fn iter_item_links(&self) -> Box<dyn Iterator<Item = &Link> + '_>
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();Sourcefn make_links_absolute(&mut self) -> Result<()>
fn make_links_absolute(&mut self) -> Result<()>
Makes all relative links absolute with respect to this object’s self href.
Sourcefn make_links_relative(&mut self) -> Result<()>
fn make_links_relative(&mut self) -> Result<()>
Makes all links relative with respect to this object’s self href.
Sourcefn remove_relative_links(&mut self)
fn remove_relative_links(&mut self)
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());Sourcefn remove_structural_links(&mut self)
fn remove_structural_links(&mut self)
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());