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 extension<E: Extension>(&self) -> Result<E> { ... }
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§
Sourcefn extensions(&self) -> &Vec<String>
fn extensions(&self) -> &Vec<String>
Returns a reference to this object’s extensions.
§Examples
use stac::Item;
use stac_extensions::Extensions;
let item = Item::new("an-id");
assert!(item.extensions().is_empty());
Sourcefn extensions_mut(&mut self) -> &mut Vec<String>
fn extensions_mut(&mut self) -> &mut Vec<String>
Returns a mutable reference to this object’s extensions.
§Examples
use stac::Item;
use stac_extensions::Extensions;
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§
Sourcefn has_extension<E: Extension>(&self) -> bool
fn has_extension<E: Extension>(&self) -> bool
Returns true if this object has the given extension.
§Examples
use stac::Item;
use stac_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>());
Sourcefn extension<E: Extension>(&self) -> Result<E>
fn extension<E: Extension>(&self) -> Result<E>
Returns an extension’s data.
§Examples
use stac::Item;
use stac_extensions::{Projection, Extensions};
let item: Item = stac::read("examples/extensions-collection/proj-example/proj-example.json").unwrap();
let projection: Projection = item.extension().unwrap();
assert_eq!(projection.code.unwrap(), "EPSG:32614");
Sourcefn add_extension<E: Extension>(&mut self)
fn add_extension<E: Extension>(&mut self)
Adds an extension’s identifier to this object.
§Examples
use stac::Item;
use stac_extensions::{Projection, Extensions};
let mut item = Item::new("an-id");
item.add_extension::<Projection>();
Sourcefn set_extension<E: Extension>(&mut self, extension: E) -> Result<()>
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;
use stac_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();
Sourcefn remove_extension<E: Extension>(&mut self)
fn remove_extension<E: Extension>(&mut self)
Removes this extension and all of its fields from this object.
§Examples
use stac::Item;
use stac_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>());
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.