rsdiff_core/id/kinds/
indexed.rs1use super::AtomicId;
6
7#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
8#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize,))]
9pub struct IndexId<Idx = usize> {
10 id: AtomicId,
11 index: Idx,
12}
13
14impl<Idx> IndexId<Idx> {
15 pub fn new(id: AtomicId, index: Idx) -> Self {
16 Self { id, index }
17 }
18 pub fn from_index(index: Idx) -> Self {
19 Self {
20 id: AtomicId::new(),
21 index,
22 }
23 }
24
25 pub fn id(&self) -> usize {
26 *self.id
27 }
28
29 pub fn index(&self) -> &Idx {
30 &self.index
31 }
32}
33
34impl<Idx> core::fmt::Display for IndexId<Idx>
35where
36 Idx: core::fmt::Display,
37{
38 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
39 write!(f, "{}({})", self.id(), self.index())
40 }
41}