@@ -12,7 +12,6 @@ use super::TimeSig;
12
12
pub type NumDiv = i64 ;
13
13
14
14
/// An enum with variants used to represent a musical division.
15
- enum_from_primitive ! {
16
15
#[ derive( Debug , Copy , Clone , RustcEncodable , RustcDecodable , PartialEq , Eq ) ]
17
16
pub enum Division {
18
17
Bar ,
@@ -26,8 +25,6 @@ pub enum Division {
26
25
TwoHundredFiftySixth ,
27
26
FiveHundredTwelfth ,
28
27
OneThousandTwentyFourth ,
29
- TotalDivisions
30
- }
31
28
}
32
29
33
30
impl Division {
@@ -61,37 +58,41 @@ impl NumCast for Division {
61
58
}
62
59
}
63
60
64
- impl ToPrimitive for Division {
65
- fn to_i64 ( & self ) -> Option < i64 > {
66
- Some ( match self {
67
- & Division :: Bar => 0 ,
68
- & Division :: Minim => 1 ,
69
- & Division :: Beat => 2 ,
70
- & Division :: Quaver => 3 ,
71
- & Division :: SemiQuaver => 4 ,
72
- & Division :: ThirtySecond => 5 ,
73
- & Division :: SixtyFourth => 6 ,
74
- & Division :: OneHundredTwentyEighth => 7 ,
75
- & Division :: TwoHundredFiftySixth => 8 ,
76
- & Division :: FiveHundredTwelfth => 9 ,
77
- & Division :: OneThousandTwentyFourth => 10 ,
78
- & Division :: TotalDivisions => 11 ,
79
- } )
61
+ impl FromPrimitive for Division {
62
+ fn from_i64 ( n : i64 ) -> Option < Self > { Self :: from_u64 ( n as u64 ) }
63
+ fn from_u64 ( n : u64 ) -> Option < Self > {
64
+ match n {
65
+ 0 => Some ( Division :: Bar ) ,
66
+ 1 => Some ( Division :: Minim ) ,
67
+ 2 => Some ( Division :: Beat ) ,
68
+ 3 => Some ( Division :: Quaver ) ,
69
+ 4 => Some ( Division :: SemiQuaver ) ,
70
+ 5 => Some ( Division :: ThirtySecond ) ,
71
+ 6 => Some ( Division :: SixtyFourth ) ,
72
+ 7 => Some ( Division :: OneHundredTwentyEighth ) ,
73
+ 8 => Some ( Division :: TwoHundredFiftySixth ) ,
74
+ 9 => Some ( Division :: FiveHundredTwelfth ) ,
75
+ 10 => Some ( Division :: OneThousandTwentyFourth ) ,
76
+ _ => None ,
77
+ }
80
78
}
79
+ }
80
+
81
+ impl ToPrimitive for Division {
82
+ fn to_i64 ( & self ) -> Option < i64 > { self . to_u64 ( ) . map ( |n| n as i64 ) }
81
83
fn to_u64 ( & self ) -> Option < u64 > {
82
- Some ( match self {
83
- & Division :: Bar => 0 ,
84
- & Division :: Minim => 1 ,
85
- & Division :: Beat => 2 ,
86
- & Division :: Quaver => 3 ,
87
- & Division :: SemiQuaver => 4 ,
88
- & Division :: ThirtySecond => 5 ,
89
- & Division :: SixtyFourth => 6 ,
90
- & Division :: OneHundredTwentyEighth => 7 ,
91
- & Division :: TwoHundredFiftySixth => 8 ,
92
- & Division :: FiveHundredTwelfth => 9 ,
93
- & Division :: OneThousandTwentyFourth => 10 ,
94
- & Division :: TotalDivisions => 11 ,
84
+ Some ( match * self {
85
+ Division :: Bar => 0 ,
86
+ Division :: Minim => 1 ,
87
+ Division :: Beat => 2 ,
88
+ Division :: Quaver => 3 ,
89
+ Division :: SemiQuaver => 4 ,
90
+ Division :: ThirtySecond => 5 ,
91
+ Division :: SixtyFourth => 6 ,
92
+ Division :: OneHundredTwentyEighth => 7 ,
93
+ Division :: TwoHundredFiftySixth => 8 ,
94
+ Division :: FiveHundredTwelfth => 9 ,
95
+ Division :: OneThousandTwentyFourth => 10 ,
95
96
} )
96
97
}
97
98
}
@@ -113,12 +114,11 @@ impl Sub<isize> for Division {
113
114
/// The 'Division Type'. Used for handling 'Thirds'.
114
115
/// Whole represents a Whole division, while TwoThirds
115
116
/// represents two thirds of a division.
116
- enum_from_primitive ! {
117
117
#[ derive( Debug , Copy , Clone , RustcEncodable , RustcDecodable , PartialEq , Eq ) ]
118
118
pub enum DivType {
119
119
Whole , TwoThirds
120
120
}
121
- }
121
+
122
122
123
123
impl DivType {
124
124
pub fn from_isize < T : NumCast > ( num : T ) -> DivType {
@@ -132,17 +132,23 @@ impl NumCast for DivType {
132
132
}
133
133
}
134
134
135
- impl ToPrimitive for DivType {
136
- fn to_i64 ( & self ) -> Option < i64 > {
137
- Some ( match self {
138
- & DivType :: Whole => 0i64 ,
139
- & DivType :: TwoThirds => 1i64 ,
140
- } )
135
+ impl FromPrimitive for DivType {
136
+ fn from_i64 ( n : i64 ) -> Option < Self > { Self :: from_u64 ( n as u64 ) }
137
+ fn from_u64 ( n : u64 ) -> Option < Self > {
138
+ match n {
139
+ 0 => Some ( DivType :: Whole ) ,
140
+ 1 => Some ( DivType :: TwoThirds ) ,
141
+ _ => None ,
142
+ }
141
143
}
144
+ }
145
+
146
+ impl ToPrimitive for DivType {
147
+ fn to_i64 ( & self ) -> Option < i64 > { self . to_u64 ( ) . map ( |n| n as i64 ) }
142
148
fn to_u64 ( & self ) -> Option < u64 > {
143
149
Some ( match self {
144
- & DivType :: Whole => 0u64 ,
145
- & DivType :: TwoThirds => 1u64 ,
150
+ & DivType :: Whole => 0 ,
151
+ & DivType :: TwoThirds => 1 ,
146
152
} )
147
153
}
148
154
}
0 commit comments