Skip to content

Commit afb18d9

Browse files
committed
align baggage.remove implementation
1 parent a423ad2 commit afb18d9

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

opentelemetry/src/baggage.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ impl Baggage {
161161

162162
/// Removes a name from the baggage, returning the value
163163
/// corresponding to the name if the pair was previously in the map.
164-
pub fn remove<K: Into<Key>>(&mut self, key: K) -> Option<(Value, BaggageMetadata)> {
165-
self.inner.remove(&key.into())
164+
pub fn remove<K: AsRef<str>>(&mut self, key: K) -> Option<(Value, BaggageMetadata)> {
165+
self.inner.remove(key.as_ref())
166166
}
167167

168168
/// Returns the number of attributes for this baggage
@@ -608,4 +608,25 @@ mod tests {
608608
assert!(b.to_string().contains("bar=2;yellow"));
609609
assert!(b.to_string().contains("foo=1;red;state=on"));
610610
}
611+
612+
#[test]
613+
fn test_crud_operations() {
614+
let mut baggage = Baggage::default();
615+
assert!(baggage.is_empty());
616+
617+
// create
618+
baggage.insert("foo", "1");
619+
assert_eq!(baggage.len(), 1);
620+
621+
// get
622+
assert_eq!(baggage.get("foo"), Some(&Value::from("1")));
623+
624+
// update
625+
baggage.insert("foo", "2");
626+
assert_eq!(baggage.get("foo"), Some(&Value::from("2")));
627+
628+
// delete
629+
baggage.remove("foo");
630+
assert!(baggage.is_empty());
631+
}
611632
}

0 commit comments

Comments
 (0)