1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::{ConcurrentVec, elem::ConcurrentElement};
use orx_pinned_vec::IntoConcurrentPinnedVec;
impl<T, P> ConcurrentVec<T, P>
where
P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
T: PartialEq,
{
/// Returns the index of the first element equal to the given `value`.
/// Returns None if the value is absent.
///
/// # Examples
///
/// ```
/// use orx_concurrent_vec::*;
///
/// let vec = ConcurrentVec::from_iter(['a', 'b', 'c']);
///
/// assert_eq!(vec.index_of(&'c'), Some(2));
/// assert_eq!(vec.index_of(&'d'), None);
/// ```
pub fn index_of(&self, value: &T) -> Option<usize> {
self.iter().position(|e| e == value)
}
/// Returns whether an element equal to the given `value` exists or not.
///
/// # Examples
///
/// ```
/// use orx_concurrent_vec::*;
///
/// let vec = ConcurrentVec::from_iter(['a', 'b', 'c']);
///
/// assert_eq!(vec.contains(&'c'), true);
/// assert_eq!(vec.contains(&'d'), false);
/// ```
pub fn contains(&self, value: &T) -> bool {
self.index_of(value).is_some()
}
}