Skip to content

Commit

Permalink
feat: Add Fields impl for Link
Browse files Browse the repository at this point in the history
  • Loading branch information
alekzvik committed Dec 3, 2024
1 parent 5cd2c5f commit c21abf9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion crates/types/src/link.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -688,6 +688,16 @@ impl Link {
}
}

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

fn fields_mut(&mut self) -> &mut Map<String, Value> {
&mut self.additional_fields
}
}

#[cfg(test)]
mod tests {
use super::Link;
Expand All @@ -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");
Expand Down

0 comments on commit c21abf9

Please sign in to comment.