Skip to content

Commit 9185a52

Browse files
authored
fix: Inconsistent implementation of IntoIterator (#148)
1 parent 2ed321e commit 9185a52

2 files changed

Lines changed: 167 additions & 7 deletions

File tree

tpchgen/src/generators.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a> RegionGenerator<'a> {
254254
}
255255
}
256256

257-
impl<'a> IntoIterator for &'a RegionGenerator<'a> {
257+
impl<'a> IntoIterator for RegionGenerator<'a> {
258258
type Item = Region<'a>;
259259
type IntoIter = RegionGeneratorIterator<'a>;
260260

@@ -466,7 +466,7 @@ impl<'a> PartGenerator<'a> {
466466
}
467467
}
468468

469-
impl<'a> IntoIterator for &'a PartGenerator<'a> {
469+
impl<'a> IntoIterator for PartGenerator<'a> {
470470
type Item = Part<'a>;
471471
type IntoIter = PartGeneratorIterator<'a>;
472472

@@ -741,7 +741,7 @@ impl<'a> SupplierGenerator<'a> {
741741
}
742742
}
743743

744-
impl<'a> IntoIterator for &'a SupplierGenerator<'a> {
744+
impl<'a> IntoIterator for SupplierGenerator<'a> {
745745
type Item = Supplier;
746746
type IntoIter = SupplierGeneratorIterator<'a>;
747747

@@ -1043,7 +1043,7 @@ impl<'a> CustomerGenerator<'a> {
10431043
}
10441044
}
10451045

1046-
impl<'a> IntoIterator for &'a CustomerGenerator<'a> {
1046+
impl<'a> IntoIterator for CustomerGenerator<'a> {
10471047
type Item = Customer<'a>;
10481048
type IntoIter = CustomerGeneratorIterator<'a>;
10491049

@@ -1264,7 +1264,7 @@ impl<'a> PartSuppGenerator<'a> {
12641264
}
12651265
}
12661266

1267-
impl<'a> IntoIterator for &'a PartSuppGenerator<'a> {
1267+
impl<'a> IntoIterator for PartSuppGenerator<'a> {
12681268
type Item = PartSupp<'a>;
12691269
type IntoIter = PartSuppGeneratorIterator<'a>;
12701270

@@ -1585,7 +1585,7 @@ impl<'a> OrderGenerator<'a> {
15851585
}
15861586
}
15871587

1588-
impl<'a> IntoIterator for &'a OrderGenerator<'a> {
1588+
impl<'a> IntoIterator for OrderGenerator<'a> {
15891589
type Item = Order<'a>;
15901590
type IntoIter = OrderGeneratorIterator<'a>;
15911591

@@ -1986,7 +1986,7 @@ impl<'a> LineItemGenerator<'a> {
19861986
}
19871987
}
19881988

1989-
impl<'a> IntoIterator for &'a LineItemGenerator<'a> {
1989+
impl<'a> IntoIterator for LineItemGenerator<'a> {
19901990
type Item = LineItem<'a>;
19911991
type IntoIter = LineItemGeneratorIterator<'a>;
19921992

tpchgen/tests/integration_tests.rs

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,163 @@ fn test_lineitem_sf_0_01() {
204204
item.to_string()
205205
})
206206
}
207+
208+
struct TestIntoIterator<G>
209+
where
210+
G: IntoIterator,
211+
G::Item: std::fmt::Display,
212+
{
213+
generator: Option<G>,
214+
}
215+
216+
impl<G> TestIntoIterator<G>
217+
where
218+
G: IntoIterator,
219+
G::Item: std::fmt::Display,
220+
{
221+
fn new(generator: G) -> Self {
222+
Self {
223+
generator: Some(generator),
224+
}
225+
}
226+
227+
pub fn to_string_vec(&mut self, take_num: i32) -> Vec<String> {
228+
if let Some(generator) = self.generator.take() {
229+
generator
230+
.into_iter()
231+
.take(take_num as usize)
232+
.map(|item| item.to_string())
233+
.collect()
234+
} else {
235+
vec![]
236+
}
237+
}
238+
}
239+
240+
#[test]
241+
fn test_nation_into_iter() {
242+
{
243+
assert_eq!(
244+
TestIntoIterator::new(NationGenerator::default())
245+
.to_string_vec(5)
246+
.len(),
247+
5
248+
);
249+
}
250+
{
251+
let nation = NationGenerator::default();
252+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
253+
}
254+
}
255+
256+
#[test]
257+
fn test_region_into_iter() {
258+
{
259+
assert_eq!(
260+
TestIntoIterator::new(RegionGenerator::default())
261+
.to_string_vec(5)
262+
.len(),
263+
5
264+
);
265+
}
266+
{
267+
let nation = RegionGenerator::default();
268+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
269+
}
270+
}
271+
272+
#[test]
273+
fn test_part_into_iter() {
274+
{
275+
assert_eq!(
276+
TestIntoIterator::new(PartGenerator::new(0.01, 1, 1))
277+
.to_string_vec(5)
278+
.len(),
279+
5
280+
);
281+
}
282+
{
283+
let nation = PartGenerator::new(0.01, 1, 1);
284+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
285+
}
286+
}
287+
288+
#[test]
289+
fn test_supplier_into_iter() {
290+
{
291+
assert_eq!(
292+
TestIntoIterator::new(SupplierGenerator::new(0.01, 1, 1))
293+
.to_string_vec(5)
294+
.len(),
295+
5
296+
);
297+
}
298+
{
299+
let nation = SupplierGenerator::new(0.01, 1, 1);
300+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
301+
}
302+
}
303+
304+
#[test]
305+
fn test_partsupp_into_iter() {
306+
{
307+
assert_eq!(
308+
TestIntoIterator::new(PartSuppGenerator::new(0.01, 1, 1))
309+
.to_string_vec(5)
310+
.len(),
311+
5
312+
);
313+
}
314+
{
315+
let nation = PartSuppGenerator::new(0.01, 1, 1);
316+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
317+
}
318+
}
319+
320+
#[test]
321+
fn test_customer_into_iter() {
322+
{
323+
assert_eq!(
324+
TestIntoIterator::new(CustomerGenerator::new(0.01, 1, 1))
325+
.to_string_vec(5)
326+
.len(),
327+
5
328+
);
329+
}
330+
{
331+
let nation = CustomerGenerator::new(0.01, 1, 1);
332+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
333+
}
334+
}
335+
336+
#[test]
337+
fn test_orders_into_iter() {
338+
{
339+
assert_eq!(
340+
TestIntoIterator::new(OrderGenerator::new(0.01, 1, 1))
341+
.to_string_vec(5)
342+
.len(),
343+
5
344+
);
345+
}
346+
{
347+
let nation = OrderGenerator::new(0.01, 1, 1);
348+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
349+
}
350+
}
351+
352+
#[test]
353+
fn test_lineitem_into_iter() {
354+
{
355+
assert_eq!(
356+
TestIntoIterator::new(LineItemGenerator::new(0.01, 1, 1))
357+
.to_string_vec(5)
358+
.len(),
359+
5
360+
);
361+
}
362+
{
363+
let nation = LineItemGenerator::new(0.01, 1, 1);
364+
assert_eq!(TestIntoIterator::new(nation).to_string_vec(5).len(), 5);
365+
}
366+
}

0 commit comments

Comments
 (0)