use crate::{
propagation::{Extractor, Injector},
Context,
};
use std::fmt::Debug;
use std::slice;
pub trait TextMapPropagator: Debug {
fn inject(&self, injector: &mut dyn Injector) {
self.inject_context(&Context::current(), injector)
}
fn inject_context(&self, cx: &Context, injector: &mut dyn Injector);
fn extract(&self, extractor: &dyn Extractor) -> Context {
self.extract_with_context(&Context::current(), extractor)
}
fn extract_with_context(&self, cx: &Context, extractor: &dyn Extractor) -> Context;
fn fields(&self) -> FieldIter<'_>;
}
#[derive(Debug)]
pub struct FieldIter<'a>(slice::Iter<'a, String>);
impl<'a> FieldIter<'a> {
pub fn new(fields: &'a [String]) -> Self {
FieldIter(fields.iter())
}
}
impl<'a> Iterator for FieldIter<'a> {
type Item = &'a str;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|field| field.as_str())
}
}