1crate::ix!();
2
3#[derive(RandConstruct,Hash,Debug,Clone,Serialize,Deserialize,PartialEq,Eq)]
5pub enum Meter {
6
7 #[rand_construct(p=0.7)]
8 Standard(LyricalMeter),
9
10 #[rand_construct(p=0.3)]
11 Other(OtherMeter),
12}
13
14impl AIDescriptor for Meter {
15
16 fn ai(&self) -> Cow<'_,str> {
19 match self {
20 Meter::Standard(ref meter) => meter.ai(),
21 Meter::Other(ref meter) => meter.text(),
22 }
23 }
24
25 fn ai_alt(&self) -> Cow<'_,str> {
26 match self {
27 Meter::Standard(ref meter) => meter.ai_alt(),
28 Meter::Other(ref meter) => meter.text(),
29 }
30 }
31}
32
33impl Default for Meter {
34 fn default() -> Self {
35 Self::Standard(LyricalMeter::default())
36 }
37}
38
39impl Meter {
40 pub fn is_same_type(&self, other: &Meter) -> bool {
42 matches!((self, other), (Meter::Standard(_), Meter::Standard(_)) | (Meter::Other(_), Meter::Other(_)))
43 }
44
45 pub fn as_standard(&self) -> Option<&LyricalMeter> {
47 if let Meter::Standard(ref lyrical_meter) = self {
48 Some(lyrical_meter)
49 } else {
50 None
51 }
52 }
53
54 pub fn as_other(&self) -> Option<&OtherMeter> {
56 if let Meter::Other(ref other_meter) = self {
57 Some(other_meter)
58 } else {
59 None
60 }
61 }
62}