use crate::propagation::TextMapPropagator;
use crate::sdk::propagation::TextMapCompositePropagator;
use std::sync::RwLock;
lazy_static::lazy_static! {
static ref GLOBAL_TEXT_MAP_PROPAGATOR: RwLock<Box<dyn TextMapPropagator + Send + Sync>> = RwLock::new(Box::new(TextMapCompositePropagator::new(vec![])));
static ref DEFAULT_TEXT_MAP_PROPAGATOR: TextMapCompositePropagator = TextMapCompositePropagator::new(vec![]);
}
pub fn set_text_map_propagator<P: TextMapPropagator + Send + Sync + 'static>(propagator: P) {
let _lock = GLOBAL_TEXT_MAP_PROPAGATOR
.write()
.map(|mut global_propagator| *global_propagator = Box::new(propagator));
}
pub fn get_text_map_propagator<T, F>(mut f: F) -> T
where
F: FnMut(&dyn TextMapPropagator) -> T,
{
GLOBAL_TEXT_MAP_PROPAGATOR
.read()
.map(|propagator| f(&**propagator))
.unwrap_or_else(|_| f(&*DEFAULT_TEXT_MAP_PROPAGATOR as &dyn TextMapPropagator))
}