orx_concurrent_vec/common_traits/
debug.rs1use crate::{ConcurrentElement, ConcurrentSlice, ConcurrentVec};
2use core::fmt::Debug;
3use orx_fixed_vec::IntoConcurrentPinnedVec;
4
5impl<T: Debug> Debug for ConcurrentElement<T> {
6 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
7 self.map(|x| write!(f, "{x:?}"))
8 }
9}
10
11impl<T, P> Debug for ConcurrentVec<T, P>
12where
13 P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
14 T: Debug,
15{
16 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
17 fmt_elems_iter(f, self.iter())
18 }
19}
20
21impl<T, P> Debug for ConcurrentSlice<'_, T, P>
22where
23 P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
24 T: Debug,
25{
26 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
27 fmt_elems_iter(f, self.iter())
28 }
29}
30
31fn fmt_elems_iter<'a, T, I>(f: &mut core::fmt::Formatter<'_>, mut iter: I) -> core::fmt::Result
34where
35 T: Debug + 'a,
36 I: Iterator<Item = &'a ConcurrentElement<T>>,
37{
38 write!(f, "[")?;
39 if let Some(first) = iter.next() {
40 first.map(|x| write!(f, "{x:?}"))?;
41 for elem in iter {
42 elem.map(|x| write!(f, ", {x:?}"))?;
43 }
44 }
45 write!(f, "]")
46}