Trait stac::extensions::Extensions

source ·
pub trait Extensions: Fields {
    // Required methods
    fn extensions(&self) -> &Vec<String>;
    fn extensions_mut(&mut self) -> &mut Vec<String>;

    // Provided methods
    fn has_extension<E: Extension>(&self) -> bool { ... }
    fn add_extension<E: Extension>(&mut self) { ... }
    fn set_extension<E: Extension>(&mut self, extension: E) -> Result<()> { ... }
    fn remove_extension<E: Extension>(&mut self) { ... }
}
Expand description

A trait for objects that may have STAC extensions.

Required Methods§

source

fn extensions(&self) -> &Vec<String>

Returns a reference to this object’s extensions.

§Examples
use stac::{Extensions, Item};
let item = Item::new("an-id");
assert!(item.extensions().is_empty());
source

fn extensions_mut(&mut self) -> &mut Vec<String>

Returns a mutable reference to this object’s extensions.

§Examples
use stac::{Extensions, Item};
let mut item = Item::new("an-id");
item.extensions_mut().push("https://stac-extensions.github.io/raster/v1.1.0/schema.json".to_string());

Provided Methods§

source

fn has_extension<E: Extension>(&self) -> bool

Returns true if this object has the given extension.

§Examples
use stac::{Item, extensions::{Projection, Extensions}};
let mut item = Item::new("an-id");
assert!(!item.has_extension::<Projection>());
let projection = Projection { code: Some("EPSG:4326".to_string()), ..Default::default() };
item.set_extension(projection).unwrap();
assert!(item.has_extension::<Projection>());
source

fn add_extension<E: Extension>(&mut self)

Adds an extension’s identifier to this object.

§Examples
use stac::{Item, extensions::{Projection, Extensions}};
let mut item = Item::new("an-id");
item.add_extension::<Projection>();
source

fn set_extension<E: Extension>(&mut self, extension: E) -> Result<()>

Sets an extension’s data and adds its schema to this object’s extensions.

This will remove any previous versions of this extension.

§Examples
use stac::{Item, extensions::{Projection, Extensions}};
let mut item = Item::new("an-id");
let projection = Projection { code: Some("EPSG:4326".to_string()), ..Default::default() };
item.set_extension(projection).unwrap();
source

fn remove_extension<E: Extension>(&mut self)

Removes this extension and all of its fields from this object.

§Examples
use stac::{Item, extensions::{Projection, Extensions}};
let mut item: Item = stac::read("examples/extensions-collection/proj-example/proj-example.json").unwrap();
assert!(item.has_extension::<Projection>());
item.remove_extension::<Projection>();
assert!(!item.has_extension::<Projection>());

Object Safety§

This trait is not object safe.

Implementors§