Skip to content

Commit

Permalink
Merge georust#156
Browse files Browse the repository at this point in the history
156: return owned value when removing item, same as underlying json API r=frewsxcv a=michaelkirk



Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
  • Loading branch information
bors[bot] and michaelkirk committed Dec 28, 2020
2 parents bb36c5a + 6a5dc2f commit 7f1de48
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ impl Feature {
self.properties.as_mut().unwrap().insert(key, value);
}

/// Delete a property if it is set, otherwise do nothing.
pub fn remove_property(&mut self, key: impl AsRef<str>) {
if let Some(props) = self.properties.as_mut() {
props.remove(key.as_ref());
}
/// Removes a key from the `properties` map, returning the value at the key if the key
/// was previously in the `properties` map.
pub fn remove_property(&mut self, key: impl AsRef<str>) -> Option<JsonValue> {
self.properties.as_mut().and_then(|props| props.remove(key.as_ref()))
}

/// The number of properties
Expand Down Expand Up @@ -422,7 +421,7 @@ mod tests {
vec![(&"foo".to_string(), &json!(12))]
);

feature.remove_property("foo");
assert_eq!(Some(json!(12)), feature.remove_property("foo"));
assert_eq!(feature.property("foo"), None);
assert_eq!(feature.len_properties(), 0);
assert_eq!(feature.contains_property("foo"), false);
Expand Down

0 comments on commit 7f1de48

Please sign in to comment.