1use alloc::vec::Vec;
6use core::fmt;
7
8#[derive(Debug)]
10pub struct DuplicateItem<T, D = T> {
11    new: T,
12    duplicates: Vec<D>,
13}
14
15impl<T, D> DuplicateItem<T, D> {
16    #[doc(hidden)]
18    pub fn __internal_new(new: T, duplicates: Vec<D>) -> Self {
19        DuplicateItem { new, duplicates }
20    }
21
22    #[inline]
24    pub fn new_item(&self) -> &T {
25        &self.new
26    }
27
28    #[inline]
30    pub fn duplicates(&self) -> &[D] {
31        &self.duplicates
32    }
33
34    pub fn into_parts(self) -> (T, Vec<D>) {
36        (self.new, self.duplicates)
37    }
38}
39
40impl<T: Clone> DuplicateItem<T, &T> {
41    pub fn into_owned(self) -> DuplicateItem<T> {
47        DuplicateItem {
48            new: self.new,
49            duplicates: self.duplicates.into_iter().cloned().collect(),
50        }
51    }
52}
53
54impl<T: fmt::Debug, D: fmt::Debug> fmt::Display for DuplicateItem<T, D> {
55    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56        write!(
57            f,
58            "new item: {:?} conflicts with existing: {:?}",
59            self.new, self.duplicates
60        )
61    }
62}
63
64impl<T: fmt::Debug, D: fmt::Debug> core::error::Error for DuplicateItem<T, D> {}