crate::ix!();
#[derive(RandConstruct,Hash,Debug,Clone,Serialize,Deserialize,PartialEq,Eq)]
pub enum Meter {
#[rand_construct(p=0.7)]
Standard(LyricalMeter),
#[rand_construct(p=0.3)]
Other(OtherMeter),
}
impl AIDescriptor for Meter {
fn ai(&self) -> Cow<'_,str> {
match self {
Meter::Standard(ref meter) => meter.ai(),
Meter::Other(ref meter) => meter.text(),
}
}
fn ai_alt(&self) -> Cow<'_,str> {
match self {
Meter::Standard(ref meter) => meter.ai_alt(),
Meter::Other(ref meter) => meter.text(),
}
}
}
impl Default for Meter {
fn default() -> Self {
Self::Standard(LyricalMeter::default())
}
}
impl Meter {
pub fn is_same_type(&self, other: &Meter) -> bool {
matches!((self, other), (Meter::Standard(_), Meter::Standard(_)) | (Meter::Other(_), Meter::Other(_)))
}
pub fn as_standard(&self) -> Option<&LyricalMeter> {
if let Meter::Standard(ref lyrical_meter) = self {
Some(lyrical_meter)
} else {
None
}
}
pub fn as_other(&self) -> Option<&OtherMeter> {
if let Meter::Other(ref other_meter) = self {
Some(other_meter)
} else {
None
}
}
}