From 4c814c17ef916ab9e9fa1d13ea820e221a640398 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Wed, 4 Nov 2020 09:19:50 +0100 Subject: [PATCH] Additional traits for reference iterators Most importantly, Clone. See https://github.com/bodil/im-rs/issues/134. Piggy-backing Debug when possible, because, why not. Not implementing Copy even where it would be possible, as that could turn into footgun (iterators "forking"). Not implementing Clone on consuming iterators, as that also clones the elements and that's probably not intended. --- Cargo.toml | 4 +++- src/ring_buffer/iter.rs | 1 + src/sparse_chunk/iter.rs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c742d11..ab23393 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,9 @@ ringbuffer = ["array-ops"] [dependencies] typenum = "1.11.2" -bitmaps = "2.0.0" +#bitmaps = "2.0.0" +# TODO: Remove before merging, once bitmaps gets released (and bump version then) +bitmaps = { version = "2.0.0", git = "https://github.com/vorner/bitmaps", branch = "iter-traits" } array-ops = { version = "0.1", optional = true } refpool = { version = "0.4", optional = true } arbitrary = { version = "0.4", optional = true } diff --git a/src/ring_buffer/iter.rs b/src/ring_buffer/iter.rs index aa8d06b..9559415 100644 --- a/src/ring_buffer/iter.rs +++ b/src/ring_buffer/iter.rs @@ -11,6 +11,7 @@ use super::{index::RawIndex, RingBuffer}; use array_ops::HasLength; /// A reference iterator over a `RingBuffer`. +#[derive(Clone)] pub struct Iter<'a, A, N> where N: ChunkLength, diff --git a/src/sparse_chunk/iter.rs b/src/sparse_chunk/iter.rs index 460096c..1c7399f 100644 --- a/src/sparse_chunk/iter.rs +++ b/src/sparse_chunk/iter.rs @@ -4,6 +4,7 @@ use super::SparseChunk; use crate::types::ChunkLength; /// An iterator over references to the elements of a `SparseChunk`. +#[derive(Debug, Clone)] pub struct Iter<'a, A, N: Bits + ChunkLength> { pub(crate) indices: BitmapIter<'a, N>, pub(crate) chunk: &'a SparseChunk,