metrique_core/
inflectable_entry_impls.rs1use std::{borrow::Cow, sync::Arc};
7
8use metrique_writer_core::{EntryWriter, entry::SampleGroupElement};
9
10use crate::{InflectableEntry, namestyle::NameStyle};
11
12impl<NS: NameStyle, T: InflectableEntry<NS>> InflectableEntry<NS> for &T {
13 fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
14 (**self).write(writer)
15 }
16
17 fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
18 (**self).sample_group()
19 }
20}
21
22impl<NS: NameStyle, T: InflectableEntry<NS>> InflectableEntry<NS> for Option<T> {
23 fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
24 if let Some(entry) = self.as_ref() {
25 entry.write(writer)
26 }
27 }
28
29 fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
30 if let Some(entry) = self.as_ref() {
31 itertools::Either::Left(entry.sample_group())
32 } else {
33 itertools::Either::Right([].into_iter())
34 }
35 }
36}
37
38impl<NS: NameStyle, T: InflectableEntry<NS> + ?Sized> InflectableEntry<NS> for Box<T> {
39 fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
40 (**self).write(writer)
41 }
42
43 fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
44 (**self).sample_group()
45 }
46}
47
48impl<NS: NameStyle, T: InflectableEntry<NS> + ?Sized> InflectableEntry<NS> for Arc<T> {
49 fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
50 (**self).write(writer)
51 }
52
53 fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
54 (**self).sample_group()
55 }
56}
57
58impl<NS: NameStyle, T: InflectableEntry<NS> + ToOwned + ?Sized> InflectableEntry<NS>
59 for Cow<'_, T>
60{
61 fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
62 (**self).write(writer)
63 }
64
65 fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> {
66 (**self).sample_group()
67 }
68}