Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proj and raster extensions #234

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions stac/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- The projection and raster extensions, the `Extension` trait, and the `Fields` trait ([#234](https://github.com/stac-utils/stac-rs/pull/234))

### Changed

- The `extensions` attribute of catalogs, collections, and items is now non-optional ([#234](https://github.com/stac-utils/stac-rs/pull/234))

## [0.5.3] - 2024-04-07

### Added
Expand Down
23 changes: 23 additions & 0 deletions stac/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::{Extensions, Fields};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use std::collections::HashMap;
Expand Down Expand Up @@ -54,6 +55,9 @@ pub struct Asset {
/// Additional fields on the asset.
#[serde(flatten)]
pub additional_fields: Map<String, Value>,

#[serde(skip)]
extensions: Vec<String>,
}

/// Trait implemented by anything that has assets.
Expand Down Expand Up @@ -107,10 +111,29 @@ impl Asset {
created: None,
updated: None,
additional_fields: Map::new(),
extensions: Vec::new(),
}
}
}

impl Fields for Asset {
fn fields(&self) -> &Map<String, Value> {
&self.additional_fields
}
fn fields_mut(&mut self) -> &mut Map<String, Value> {
&mut self.additional_fields
}
}

impl Extensions for Asset {
fn extensions(&self) -> &Vec<String> {
&self.extensions
}
fn extensions_mut(&mut self) -> &mut Vec<String> {
&mut self.extensions
}
}

#[cfg(test)]
mod tests {
use super::Asset;
Expand Down
27 changes: 20 additions & 7 deletions stac/src/catalog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Error, Extensions, Href, Link, Links, Result, STAC_VERSION};
use crate::{Error, Extensions, Fields, Href, Link, Links, Result, STAC_VERSION};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};

Expand Down Expand Up @@ -33,8 +33,9 @@ pub struct Catalog {

/// A list of extension identifiers the `Catalog` implements.
#[serde(rename = "stac_extensions")]
#[serde(skip_serializing_if = "Option::is_none")]
pub extensions: Option<Vec<String>>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub extensions: Vec<String>,

/// Identifier for the `Catalog`.
pub id: String,
Expand Down Expand Up @@ -74,7 +75,7 @@ impl Catalog {
Catalog {
r#type: CATALOG_TYPE.to_string(),
version: STAC_VERSION.to_string(),
extensions: None,
extensions: Vec::new(),
id: id.to_string(),
title: None,
description: description.to_string(),
Expand Down Expand Up @@ -122,9 +123,21 @@ impl TryFrom<Map<String, Value>> for Catalog {
}
}

impl Fields for Catalog {
fn fields(&self) -> &Map<String, Value> {
&self.additional_fields
}
fn fields_mut(&mut self) -> &mut Map<String, Value> {
&mut self.additional_fields
}
}

impl Extensions for Catalog {
fn extensions(&self) -> Option<&[String]> {
self.extensions.as_deref()
fn extensions(&self) -> &Vec<String> {
&self.extensions
}
fn extensions_mut(&mut self) -> &mut Vec<String> {
&mut self.extensions
}
}

Expand Down Expand Up @@ -154,7 +167,7 @@ mod tests {
assert_eq!(catalog.description, "a description");
assert_eq!(catalog.r#type, "Catalog");
assert_eq!(catalog.version, STAC_VERSION);
assert!(catalog.extensions.is_none());
assert!(catalog.extensions.is_empty());
assert_eq!(catalog.id, "an-id");
assert!(catalog.links.is_empty());
}
Expand Down
27 changes: 20 additions & 7 deletions stac/src/collection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Asset, Assets, Error, Extensions, Href, Link, Links, Result, STAC_VERSION};
use crate::{Asset, Assets, Error, Extensions, Fields, Href, Link, Links, Result, STAC_VERSION};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use std::collections::HashMap;
Expand Down Expand Up @@ -36,8 +36,9 @@ pub struct Collection {

/// A list of extension identifiers the `Collection` implements.
#[serde(rename = "stac_extensions")]
#[serde(skip_serializing_if = "Option::is_none")]
pub extensions: Option<Vec<String>>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub extensions: Vec<String>,

/// Identifier for the `Collection` that is unique across the provider.
pub id: String,
Expand Down Expand Up @@ -171,7 +172,7 @@ impl Collection {
Collection {
r#type: COLLECTION_TYPE.to_string(),
version: STAC_VERSION.to_string(),
extensions: None,
extensions: Vec::new(),
id: id.to_string(),
title: None,
description: description.to_string(),
Expand Down Expand Up @@ -253,9 +254,21 @@ impl Assets for Collection {
}
}

impl Fields for Collection {
fn fields(&self) -> &Map<String, Value> {
&self.additional_fields
}
fn fields_mut(&mut self) -> &mut Map<String, Value> {
&mut self.additional_fields
}
}

impl Extensions for Collection {
fn extensions(&self) -> Option<&[String]> {
self.extensions.as_deref()
fn extensions(&self) -> &Vec<String> {
&self.extensions
}
fn extensions_mut(&mut self) -> &mut Vec<String> {
&mut self.extensions
}
}

Expand Down Expand Up @@ -311,7 +324,7 @@ mod tests {
assert!(collection.assets.is_empty());
assert_eq!(collection.r#type, "Collection");
assert_eq!(collection.version, STAC_VERSION);
assert!(collection.extensions.is_none());
assert!(collection.extensions.is_empty());
assert_eq!(collection.id, "an-id");
assert!(collection.links.is_empty());
}
Expand Down
4 changes: 4 additions & 0 deletions stac/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub enum Error {
#[error("value is not a collection")]
NotACollection(Value),

/// This value is not an object.
#[error("not an object")]
NotAnObject(serde_json::Value),

/// Returned when trying to read from a url but the `reqwest` feature is not enabled.
#[error("reqwest is not enabled")]
ReqwestNotEnabled,
Expand Down
13 changes: 0 additions & 13 deletions stac/src/extensions.rs

This file was deleted.

Loading