libdd_profiling/
iter.rs

1// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4/// The [LendingIterator] is a version of an [Iterator] that can yield items
5/// with references into the lender. It is a well-known name and there are
6/// multiple crates which offer it, with differences. The needs here are
7/// small, and so rather than bring in a pre-1.0 crate, just make our own.
8pub trait LendingIterator {
9    type Item<'a>
10    where
11        Self: 'a;
12
13    fn next(&mut self) -> Option<Self::Item<'_>>;
14
15    #[allow(unused)]
16    fn count(self) -> usize;
17}
18
19/// Turn a collection of some sort into a [LendingIterator].
20pub trait IntoLendingIterator {
21    type Iter: LendingIterator;
22    fn into_lending_iter(self) -> Self::Iter;
23}