Thanks to visit codestin.com
Credit goes to docs.rs

orx_concurrent_vec/
partial_eq.rs

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