Skip to content

Commit b529bc3

Browse files
authored
Merge pull request #69 from orxfun/SplitVec-implements-Collection-and-CollectionMut
SplitVec implements Collection and CollectionMut
2 parents 0e8da9c + 74f4ad0 commit b529bc3

10 files changed

Lines changed: 30 additions & 27 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "orx-split-vec"
3-
version = "3.11.1"
3+
version = "3.12.0"
44
edition = "2021"
55
authors = ["orxfun <orx.ugur.arikan@gmail.com>"]
66
description = "An efficient dynamic capacity vector with pinned element guarantees."
@@ -10,8 +10,9 @@ keywords = ["vec", "array", "split", "fragments", "pinned"]
1010
categories = ["data-structures", "rust-patterns", "no-std"]
1111

1212
[dependencies]
13+
orx-iterable = { version = "1.1.1", default-features = false }
14+
orx-pinned-vec = "3.12"
1315
orx-pseudo-default = { version = "1.4", default-features = false }
14-
orx-pinned-vec = "3.11"
1516

1617
[[bench]]
1718
name = "serial_access"

src/common_traits/iterator/iter.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
use super::reductions;
2-
use crate::fragment::fragment_struct::Fragment;
2+
use crate::{fragment::fragment_struct::Fragment, Growth, SplitVec};
33
use core::iter::FusedIterator;
44

5+
impl<'a, T, G: Growth> IntoIterator for &'a SplitVec<T, G> {
6+
type Item = &'a T;
7+
type IntoIter = Iter<'a, T>;
8+
9+
fn into_iter(self) -> Self::IntoIter {
10+
Self::IntoIter::new(&self.fragments)
11+
}
12+
}
13+
514
/// Iterator over the `SplitVec`.
615
///
716
/// This struct is created by `SplitVec::iter()` method.

src/common_traits/iterator/iter_mut.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
use crate::fragment::fragment_struct::Fragment;
1+
use crate::{fragment::fragment_struct::Fragment, Growth, SplitVec};
22
use core::iter::FusedIterator;
33

4+
impl<'a, T, G: Growth> IntoIterator for &'a mut SplitVec<T, G> {
5+
type Item = &'a mut T;
6+
type IntoIter = IterMut<'a, T>;
7+
8+
fn into_iter(self) -> Self::IntoIter {
9+
Self::IntoIter::new(&mut self.fragments)
10+
}
11+
}
12+
413
/// Mutable iterator over the `SplitVec`.
514
///
615
/// This struct is created by `SplitVec::iter_mut()` method.

src/common_traits/iterator/tests/into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{test_all_growth_types, Growth, SplitVec};
22
use alloc::vec::Vec;
3-
use orx_pinned_vec::PinnedVec;
3+
use orx_pinned_vec::*;
44

55
#[test]
66
fn iter() {

src/common_traits/iterator/tests/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{test_all_growth_types, Growth, SplitVec};
22
use alloc::vec::Vec;
3-
use orx_pinned_vec::PinnedVec;
3+
use orx_pinned_vec::*;
44

55
#[test]
66
fn iter() {

src/common_traits/iterator/tests/iter_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{test_all_growth_types, Growth, SplitVec};
22
use alloc::vec::Vec;
3-
use orx_pinned_vec::PinnedVec;
3+
use orx_pinned_vec::*;
44

55
#[test]
66
fn iter_mut() {

src/common_traits/iterator/tests/iter_mut_rev.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{test_all_growth_types, Growth, SplitVec};
22
use alloc::vec::Vec;
3-
use orx_pinned_vec::PinnedVec;
3+
use orx_pinned_vec::*;
44

55
#[test]
66
fn iter_mut() {

src/common_traits/iterator/tests/iter_rev.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{test_all_growth_types, Growth, SplitVec};
22
use alloc::vec::Vec;
3-
use orx_pinned_vec::PinnedVec;
3+
use orx_pinned_vec::*;
44

55
#[test]
66
fn iter() {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub use growth::{
4949
linear::Linear,
5050
recursive::Recursive,
5151
};
52+
pub use orx_iterable::{Collection, CollectionMut, Iterable};
5253
pub use orx_pinned_vec::{
5354
ConcurrentPinnedVec, IntoConcurrentPinnedVec, PinnedVec, PinnedVecGrowthError,
5455
};

src/pinned_vec.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{algorithms, Fragment, Growth, SplitVec};
66
use alloc::vec::Vec;
77
use core::cmp::Ordering;
88
use core::ops::RangeBounds;
9+
use orx_iterable::Collection;
910
use orx_pinned_vec::utils::slice;
1011
use orx_pinned_vec::{CapacityState, PinnedVec};
1112
use orx_pseudo_default::PseudoDefault;
@@ -20,16 +21,6 @@ impl<T, G: Growth> PseudoDefault for SplitVec<T, G> {
2021
}
2122

2223
impl<T, G: Growth> PinnedVec<T> for SplitVec<T, G> {
23-
type Iter<'a>
24-
= crate::common_traits::iterator::iter::Iter<'a, T>
25-
where
26-
T: 'a,
27-
Self: 'a;
28-
type IterMut<'a>
29-
= crate::common_traits::iterator::iter_mut::IterMut<'a, T>
30-
where
31-
T: 'a,
32-
Self: 'a;
3324
type IterRev<'a>
3425
= crate::common_traits::iterator::iter_rev::IterRev<'a, T>
3526
where
@@ -625,14 +616,6 @@ impl<T, G: Growth> PinnedVec<T> for SplitVec<T, G> {
625616
}
626617
}
627618

628-
fn iter(&self) -> Self::Iter<'_> {
629-
Self::Iter::new(&self.fragments)
630-
}
631-
632-
fn iter_mut(&mut self) -> Self::IterMut<'_> {
633-
Self::IterMut::new(&mut self.fragments)
634-
}
635-
636619
fn iter_rev(&self) -> Self::IterRev<'_> {
637620
Self::IterRev::new(&self.fragments)
638621
}

0 commit comments

Comments
 (0)