diff --git a/crates/types/src/link.rs b/crates/types/src/link.rs index ed6372db..1e86cd15 100644 --- a/crates/types/src/link.rs +++ b/crates/types/src/link.rs @@ -1,6 +1,6 @@ //! Links. -use crate::{mime::APPLICATION_GEOJSON, Error, Href, Result, SelfHref}; +use crate::{mime::APPLICATION_GEOJSON, Error, Fields, Href, Result, SelfHref}; use mime::APPLICATION_JSON; use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; @@ -688,6 +688,16 @@ impl Link { } } +impl Fields for Link { + fn fields(&self) -> &Map { + &self.additional_fields + } + + fn fields_mut(&mut self) -> &mut Map { + &mut self.additional_fields + } +} + #[cfg(test)] mod tests { use super::Link; @@ -701,6 +711,25 @@ mod tests { assert!(link.title.is_none()); } + mod fields { + use serde_json::Value; + use stac::{Fields, Link}; + + #[test] + fn empty() { + let link = Link::new("an-href", "a-rel"); + assert!(link.fields().is_empty()); + } + + #[test] + fn set_get() { + let mut link = Link::new("an-href", "a-rel"); + _ = link.set_field("some", "value"); + assert!(link.field("some") == Some(&Value::from("value"))); + assert!(*link.fields() == link.additional_fields); + } + } + #[test] fn skip_serializing() { let link = Link::new("an-href", "a-rel");