pub trait BaggageExt {
// Required methods
fn with_baggage<T: Into<Baggage>>(&self, baggage: T) -> Self;
fn current_with_baggage<T: Into<Baggage>>(baggage: T) -> Self;
fn with_cleared_baggage(&self) -> Self;
fn baggage(&self) -> &Baggage;
}
Expand description
Methods for sorting and retrieving baggage data in a context.
Required Methods§
Sourcefn with_baggage<T: Into<Baggage>>(&self, baggage: T) -> Self
fn with_baggage<T: Into<Baggage>>(&self, baggage: T) -> Self
Returns a clone of the given context with the included name/value pairs.
§Examples
use opentelemetry::{baggage::{Baggage, BaggageExt}, Context, KeyValue, StringValue};
// Explicit `Baggage` creation
let mut baggage = Baggage::new();
let _ = baggage.insert("my-name", "my-value");
let cx = Context::map_current(|cx| {
cx.with_baggage(baggage)
});
// Passing an iterator
let cx = Context::map_current(|cx| {
cx.with_baggage([KeyValue::new("my-name", "my-value")])
});
assert_eq!(
cx.baggage().get("my-name"),
Some(&StringValue::from("my-value")),
)
Sourcefn current_with_baggage<T: Into<Baggage>>(baggage: T) -> Self
fn current_with_baggage<T: Into<Baggage>>(baggage: T) -> Self
Returns a clone of the current context with the included name/value pairs.
§Examples
use opentelemetry::{baggage::{Baggage, BaggageExt}, Context, StringValue};
let mut baggage = Baggage::new();
let _ = baggage.insert("my-name", "my-value");
let cx = Context::current_with_baggage(baggage);
assert_eq!(
cx.baggage().get("my-name"),
Some(&StringValue::from("my-value")),
)
Sourcefn with_cleared_baggage(&self) -> Self
fn with_cleared_baggage(&self) -> Self
Returns a clone of the given context with no baggage.
§Examples
use opentelemetry::{baggage::BaggageExt, Context};
let cx = Context::map_current(|cx| cx.with_cleared_baggage());
assert_eq!(cx.baggage().len(), 0);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.