Skip to content

Commit 3868eba

Browse files
committed
Removed buggy enum_primitive macro crate in favour of implementations.
1 parent 615ed38 commit 3868eba

File tree

3 files changed

+49
-45
lines changed

3 files changed

+49
-45
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name = "time_calc"
44
description = "A library for music/DSP time conversions! Provides functions and methods for converting between ticks, ms, samples, bars, beats and measures."
5-
version = "0.9.10"
5+
version = "0.9.11"
66
authors = ["[email protected]"]
77
readme = "README.md"
88
keywords = ["time", "dsp", "audio", "music", "conversion"]
@@ -11,6 +11,5 @@ repository = "https://github.com/RustAudio/time_calc.git"
1111
homepage = "https://github.com/RustAudio/time_calc"
1212

1313
[dependencies]
14-
enum_primitive = "*"
1514
num = "*"
1615
rustc-serialize = "*"

src/division.rs

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use super::TimeSig;
1212
pub type NumDiv = i64;
1313

1414
/// An enum with variants used to represent a musical division.
15-
enum_from_primitive!{
1615
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, PartialEq, Eq)]
1716
pub enum Division {
1817
Bar,
@@ -26,8 +25,6 @@ pub enum Division {
2625
TwoHundredFiftySixth,
2726
FiveHundredTwelfth,
2827
OneThousandTwentyFourth,
29-
TotalDivisions
30-
}
3128
}
3229

3330
impl Division {
@@ -61,37 +58,41 @@ impl NumCast for Division {
6158
}
6259
}
6360

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+
}
8078
}
79+
}
80+
81+
impl ToPrimitive for Division {
82+
fn to_i64(&self) -> Option<i64> { self.to_u64().map(|n| n as i64) }
8183
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,
9596
})
9697
}
9798
}
@@ -113,12 +114,11 @@ impl Sub<isize> for Division {
113114
/// The 'Division Type'. Used for handling 'Thirds'.
114115
/// Whole represents a Whole division, while TwoThirds
115116
/// represents two thirds of a division.
116-
enum_from_primitive! {
117117
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, PartialEq, Eq)]
118118
pub enum DivType {
119119
Whole, TwoThirds
120120
}
121-
}
121+
122122

123123
impl DivType {
124124
pub fn from_isize<T: NumCast>(num: T) -> DivType {
@@ -132,17 +132,23 @@ impl NumCast for DivType {
132132
}
133133
}
134134

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+
}
141143
}
144+
}
145+
146+
impl ToPrimitive for DivType {
147+
fn to_i64(&self) -> Option<i64> { self.to_u64().map(|n| n as i64) }
142148
fn to_u64(&self) -> Option<u64> {
143149
Some(match self {
144-
&DivType::Whole => 0u64,
145-
&DivType::TwoThirds => 1u64,
150+
&DivType::Whole => 0,
151+
&DivType::TwoThirds => 1,
146152
})
147153
}
148154
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! Created by Mitchell Nordine at 03:54PM on November 02, 2014.
66
//!
77
8-
#[macro_use] extern crate enum_primitive;
98
extern crate num;
109
extern crate rustc_serialize;
1110

0 commit comments

Comments
 (0)