Skip to content

Commit 0d0298f

Browse files
committed
Fix Default implementations
1 parent 960de37 commit 0d0298f

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/lib.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ A prime generator, using the Trial Division method.
8282
Create with `let mut pset = TrialDivision::new()`, and then use `pset.iter()` to iterate over all
8383
primes.
8484
**/
85-
#[derive(Default, Clone)]
85+
#[derive(Clone)]
8686
pub struct TrialDivision {
8787
lst: Vec<u64>,
8888
}
8989

9090
const WHEEL30: [u64; 8] = [1, 7, 11, 13, 17, 19, 23, 29];
9191

92-
#[derive(Default, Copy, Clone)]
92+
#[derive(Copy, Clone)]
9393
struct Wheel30 {
9494
base: u64,
9595
ix: usize,
@@ -107,13 +107,19 @@ impl Wheel30 {
107107
}
108108
}
109109

110+
impl Default for Wheel30 {
111+
fn default() -> Self {
112+
Wheel30 { base: 0, ix: 1 }
113+
}
114+
}
115+
110116
/**
111117
A prime generator, using the Sieve of Eratosthenes method. This is asymptotically more efficient
112118
than the Trial Division method, but slower earlier on.
113119
114120
Create with `let mut pset = Sieve::new()`, and then use `pset.iter()` to iterate over all primes.
115121
**/
116-
#[derive(Default, Clone)]
122+
#[derive(Clone)]
117123
pub struct Sieve {
118124
primes: Vec<u64>,
119125
wheel: Wheel30,
@@ -142,6 +148,12 @@ impl TrialDivision {
142148
}
143149
}
144150

151+
impl Default for TrialDivision {
152+
fn default() -> Self {
153+
Self::new()
154+
}
155+
}
156+
145157
impl PrimeSetBasics for TrialDivision {
146158
/// Finds one more prime, and adds it to the list
147159
fn expand(&mut self) {
@@ -170,6 +182,12 @@ impl PrimeSetBasics for TrialDivision {
170182
}
171183
}
172184

185+
impl Default for Sieve {
186+
fn default() -> Self {
187+
Self::new()
188+
}
189+
}
190+
173191
impl Sieve {
174192
/// A new prime generator, primed with 2 and 3
175193
pub fn new() -> Sieve {

tests/basictests.rs

+10
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,13 @@ fn test_sieve() {
145145

146146
assert_eq!(sieved, trialled);
147147
}
148+
149+
// Test that the Sieve Default method works
150+
#[test]
151+
fn test_default() {
152+
let mut sieve = Sieve::default();
153+
154+
let n = sieve.get(5);
155+
156+
assert_eq!(n, 13);
157+
}

0 commit comments

Comments
 (0)