1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#[macro_export]
macro_rules! impl_audiotag_config {
    ($tag:ident) => {
        impl AudioTagConfig for $tag {
            fn config(&self) -> &Config {
                &self.config
            }
            fn set_config(&mut self, config: Config) {
                self.config = config.clone();
            }
        }
    };
}

#[macro_export]
macro_rules! impl_tag {
    ($tag:ident , $inner:ident) => {
        #[derive(Default)]
        pub struct $tag {
            inner: $inner,
            config: Config,
        }
        impl $tag {
            pub fn new() -> Self {
                Self::default()
            }
            pub fn read_from_path(path: impl AsRef<Path>) -> crate::Result<Self> {
                Ok(Self {
                    inner: $inner::read_from_path(path)?,
                    config: Config::default(),
                })
            }
        }
        impl_audiotag_config!($tag);

        impl IntoAnyTag for $tag {
            fn into_anytag(&self) -> AnyTag<'_> {
                self.into()
            }
        }

        impl AudioTag for $tag {}

        impl From<$tag> for $inner {
            fn from(inp: $tag) -> Self {
                inp.inner
            }
        }

        impl From<$inner> for $tag {
            fn from(inp: $inner) -> Self {
                Self {
                    inner: inp,
                    config: Config::default(),
                }
            }
        }
    };
}