re_entity_db/
versioned_instance_path.rs1use std::hash::Hash;
2
3use re_chunk::RowId;
4
5use crate::{InstancePath, InstancePathHash};
6
7#[derive(
14 Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
15)]
16pub struct VersionedInstancePath {
17 pub instance_path: InstancePath,
18 pub row_id: RowId,
19}
20
21impl VersionedInstancePath {
22 #[inline]
26 pub fn is_all(&self) -> bool {
27 self.instance_path.is_all()
28 }
29
30 #[inline]
31 pub fn hash(&self) -> VersionedInstancePathHash {
32 VersionedInstancePathHash {
33 instance_path_hash: self.instance_path.hash(),
34 row_id: self.row_id,
35 }
36 }
37}
38
39impl std::fmt::Display for VersionedInstancePath {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 format!("{} @ {}", self.instance_path, self.row_id).fmt(f)
42 }
43}
44
45#[derive(Clone, Copy, Eq)]
52pub struct VersionedInstancePathHash {
53 pub instance_path_hash: InstancePathHash,
54 pub row_id: RowId,
55}
56
57impl re_byte_size::SizeBytes for VersionedInstancePathHash {
58 fn heap_size_bytes(&self) -> u64 {
59 let Self {
60 instance_path_hash: _,
61 row_id: _,
62 } = self;
63 0
64 }
65
66 #[inline]
67 fn is_pod() -> bool {
68 true
69 }
70}
71
72impl std::fmt::Debug for VersionedInstancePathHash {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74 let Self {
75 instance_path_hash,
76 row_id,
77 } = self;
78 write!(
79 f,
80 "VersionedInstancePathHash({instance_path_hash:?}, {row_id})"
81 )
82 }
83}
84
85impl std::hash::Hash for VersionedInstancePathHash {
86 #[inline]
87 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
88 let Self {
89 instance_path_hash,
90 row_id,
91 } = self;
92 let InstancePathHash {
93 entity_path_hash,
94 instance,
95 } = instance_path_hash;
96
97 state.write_u64(entity_path_hash.hash64());
98 state.write_u64(instance.get());
99 state.write_u128(row_id.as_u128());
100 }
101}
102
103impl std::cmp::PartialEq for VersionedInstancePathHash {
104 #[inline]
105 fn eq(&self, other: &Self) -> bool {
106 let Self {
107 instance_path_hash,
108 row_id,
109 } = self;
110
111 instance_path_hash == &other.instance_path_hash && row_id == &other.row_id
112 }
113}
114
115impl VersionedInstancePathHash {
116 pub const NONE: Self = Self {
117 instance_path_hash: InstancePathHash::NONE,
118 row_id: RowId::ZERO,
119 };
120
121 #[inline]
122 pub fn is_some(&self) -> bool {
123 self.instance_path_hash.is_some()
124 }
125
126 #[inline]
127 pub fn is_none(&self) -> bool {
128 self.instance_path_hash.is_none()
129 }
130}
131
132impl Default for VersionedInstancePathHash {
133 fn default() -> Self {
134 Self::NONE
135 }
136}