Skip to content

Commit

Permalink
Remove HandleIter
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 22, 2023
1 parent 921b3d9 commit 4b0d6cf
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 76 deletions.
75 changes: 0 additions & 75 deletions crates/fj-core/src/objects/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,78 +125,3 @@ impl<'r, T> IntoIterator for &'r Handles<T> {
self.iter()
}
}

/// An iterator over handles to objects
///
/// This struct is returned by the respective methods of all objects that
/// reference multiple objects of the same type.
pub struct HandleIter<'r, T> {
handles: &'r Handles<T>,
next_index: usize,
}

impl<'r, T> HandleIter<'r, T> {
/// Return the n-th item
///
/// This method is unaffected by any previous calls to `next`.
pub fn nth(&self, index: usize) -> Option<&Handle<T>> {
self.handles.nth(index)
}

/// Return the n-th item, treating the iterator as circular
///
/// If the length of the iterator is `i`, then retrieving the i-th edge
/// using this method, is the same as retrieving the 0-th one.
///
/// This method is unaffected by any previous calls to `next`.
pub fn nth_circular(&self, index: usize) -> &Handle<T> {
self.handles.nth_circular(index)
}

/// Return the index of the item, if it is in this iterator
///
/// This method is unaffected by any previous calls to `next`.
pub fn index_of(&self, handle: &Handle<T>) -> Option<usize> {
self.handles.index_of(handle)
}

/// Access the item after the provided one
///
/// Returns `None`, if the provided item is not in this iterator.
pub fn after(&self, handle: &Handle<T>) -> Option<&Handle<T>> {
self.handles.after(handle)
}

/// Return iterator over the pairs of the remaining items in this iterator
pub fn pairs(self) -> impl Iterator<Item = (&'r Handle<T>, &'r Handle<T>)> {
self.handles.pairs()
}
}

impl<'r, T> Iterator for HandleIter<'r, T> {
type Item = &'r Handle<T>;

fn next(&mut self) -> Option<Self::Item> {
let handle = self.handles.inner.get(self.next_index);
self.next_index += 1;
handle
}

fn size_hint(&self) -> (usize, Option<usize>) {
let size = self.handles.inner.len();
(size, Some(size))
}
}

impl<T> ExactSizeIterator for HandleIter<'_, T> {}

// Deriving won't work, as that only derives `Clone` where `T: Clone`. But
// `HandleIter` can be `Clone`d unconditionally.
impl<T> Clone for HandleIter<'_, T> {
fn clone(&self) -> Self {
Self {
handles: self.handles,
next_index: self.next_index,
}
}
}
2 changes: 1 addition & 1 deletion crates/fj-core/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod set;
mod stores;

pub use self::{
handles::{HandleIter, Handles},
handles::Handles,
kinds::{
curve::Curve,
cycle::Cycle,
Expand Down

0 comments on commit 4b0d6cf

Please sign in to comment.