Skip to content

Commit

Permalink
implemented Handles::from_items()
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Dec 8, 2023
1 parent 3028b79 commit e5facc9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ where
}
}

/// Create a new handles collection from an iterator handles
/// Warning: Use of this function is dangerous and discouraged in most cases as there is no validity check on the handles you pass!
pub fn from_iter(
iter: impl Iterator<Item = T::FullHandleType>,
store: &'store AnnotationStore,
Expand All @@ -137,6 +139,35 @@ where
}
}

/// Create a new handles collection from an iterator of [`ResultItem<T>`]
pub fn from_items(
iter: impl Iterator<Item = ResultItem<'store, T>>,
store: &'store AnnotationStore,
) -> Self
where
T: 'store,
ResultItem<'store, T>: FullHandle<T>,
{
let mut sorted = true;
let mut v = Vec::new();
let mut prev: Option<T::FullHandleType> = None;
for item in iter {
let handle = item.fullhandle();
if let Some(p) = prev {
if p > handle {
sorted = false;
}
}
v.push(handle);
prev = Some(handle);
}
Self {
array: Cow::Owned(v),
sorted,
store,
}
}

/// Low-level method to take out the underlying vector of handles
pub fn take(self) -> Cow<'store, [T::FullHandleType]>
where
Expand Down

0 comments on commit e5facc9

Please sign in to comment.