use crate::extensions::Extensions;
use opentelemetry::KeyValue;
pub trait AttributesFactory: Send + Sync + 'static {
fn attributes(&self, size_hint: usize, ext: &Extensions) -> Vec<KeyValue>;
}
impl AttributesFactory for () {
fn attributes(&self, size_hint: usize, _ext: &Extensions) -> Vec<KeyValue> {
Vec::with_capacity(size_hint)
}
}
impl AttributesFactory for Vec<KeyValue> {
fn attributes(&self, size_hint: usize, _ext: &Extensions) -> Vec<KeyValue> {
let mut attributes = self.clone();
attributes.reserve(size_hint);
attributes
}
}
impl<F> AttributesFactory for F
where
F: Fn(usize, &Extensions) -> Vec<KeyValue> + Send + Sync + 'static,
{
fn attributes(&self, size_hint: usize, ext: &Extensions) -> Vec<KeyValue> {
(self)(size_hint, ext)
}
}