use std::{borrow::Cow, sync::Arc};
use metrique_writer_core::{EntryWriter, entry::SampleGroupElement};
use crate::{InflectableEntry, namestyle::NameStyle};
impl<NS: NameStyle, T: InflectableEntry<NS>> InflectableEntry<NS> for &T {
fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
(**self).write(writer)
}
fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
(**self).sample_group()
}
fn descriptors(&self) -> metrique_writer_core::Descriptors<'_> {
(**self).descriptors()
}
}
impl<NS: NameStyle, T: InflectableEntry<NS>> InflectableEntry<NS> for Option<T> {
fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
if let Some(entry) = self.as_ref() {
entry.write(writer)
}
}
fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
self.as_ref().into_iter().flat_map(|e| e.sample_group())
}
fn descriptors(&self) -> metrique_writer_core::Descriptors<'_> {
match self.as_ref() {
Some(e) => e.descriptors(),
None => metrique_writer_core::Descriptors::available(std::iter::empty()),
}
}
}
impl<NS: NameStyle, T: InflectableEntry<NS> + ?Sized> InflectableEntry<NS> for Box<T> {
fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
(**self).write(writer)
}
fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
(**self).sample_group()
}
fn descriptors(&self) -> metrique_writer_core::Descriptors<'_> {
(**self).descriptors()
}
}
impl<NS: NameStyle, T: InflectableEntry<NS> + ?Sized> InflectableEntry<NS> for Arc<T> {
fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
(**self).write(writer)
}
fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
(**self).sample_group()
}
fn descriptors(&self) -> metrique_writer_core::Descriptors<'_> {
(**self).descriptors()
}
}
impl<NS: NameStyle, T: InflectableEntry<NS> + ToOwned + ?Sized> InflectableEntry<NS>
for Cow<'_, T>
{
fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
(**self).write(writer)
}
fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
(**self).sample_group()
}
fn descriptors(&self) -> metrique_writer_core::Descriptors<'_> {
(**self).descriptors()
}
}