use std::borrow::Cow;
macro_rules! accessor_trait {
($([$($name:tt)+] < $($ty:ty),+ >),+ $(,)?) => {
pub trait Accessor {
$(
accessor_trait! { @GETTER [$($name)+] $($ty),+ }
accessor_trait! { @SETTER [$($name)+] $($ty),+ }
accessor_trait! { @REMOVE [$($name)+] $($ty),+ }
)+
}
};
(@GETTER [$($name:tt)+] $ty:ty $(, $_ty:tt)?) => {
accessor_trait! { @GET_METHOD [$($name)+] Option<$ty> }
};
(@SETTER [$($name:tt)+] $_ty:ty, $owned_ty:tt) => {
accessor_trait! { @SETTER [$($name)+] $owned_ty }
};
(@SETTER [$($name:tt)+] $ty:ty) => {
accessor_trait! { @SET_METHOD [$($name)+] $ty }
};
(@REMOVE [$($name:tt)+] $_ty:ty, $owned_ty:tt) => {
accessor_trait! { @REMOVE [$($name)+] $owned_ty }
};
(@REMOVE [$($name:tt)+] $ty:ty) => {
accessor_trait! { @REMOVE_METHOD [$($name)+], $ty }
};
(@GET_METHOD [$name:tt $($other:tt)*] Option<$ret_ty:ty>) => {
paste::paste! {
#[doc = "Returns the " $name $(" " $other)*]
#[doc = "assert_eq!(tag." $name $(_ $other)* "(), None);"]
fn [<
$name $(_ $other)*
>] (&self) -> Option<$ret_ty> { None }
}
};
(@SET_METHOD [$name:tt $($other:tt)*] $owned_ty:ty) => {
paste::paste! {
#[doc = "Sets the " $name $(" " $other)*]
#[doc = "tag.set_" $name $(_ $other)* "(value);"]
#[doc = "assert_eq!(tag." $name $(_ $other)* "(), Some(value));"]
fn [<
set_ $name $(_ $other)*
>] (&mut self , _value: $owned_ty) {}
}
};
(@REMOVE_METHOD [$name:tt $($other:tt)*], $ty:ty) => {
paste::paste! {
#[doc = "Removes the " $name $(" " $other)*]
#[doc = "tag.set_" $name $(_ $other)* "(value);"]
#[doc = "assert_eq!(tag." $name $(_ $other)* "(), Some(value));"]
#[doc = "tag.remove_" $name $(_ $other)* "();"]
#[doc = "assert_eq!(tag." $name $(_ $other)* "(), None);"]
fn [<
remove_ $name $(_ $other)*
>] (&mut self) {}
}
};
}
accessor_trait! {
[artist]<Cow<'_, str>, String>, [title ]<Cow<'_, str>, String>,
[album ]<Cow<'_, str>, String>, [genre ]<Cow<'_, str>, String>,
[track ]<u32>, [track total]<u32>,
[disk ]<u32>, [disk total ]<u32>,
[year ]<u32>, [comment ]<Cow<'_, str>, String>,
}