Skip to content

Commit 76a5294

Browse files
committed
Prefactor: Generalize storable object keys
Rename the storage-key encoding method so implementations are no longer limited to hexadecimal output. This prepares the data store for compact keys used by larger identifiers. AI-assisted-by: OpenAI Codex
1 parent d1273bf commit 76a5294

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/data_store.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) trait StorableObject: Clone + Readable + Writeable {
2626
}
2727

2828
pub(crate) trait StorableObjectId: std::hash::Hash + PartialEq + Eq {
29-
fn encode_to_hex_str(&self) -> String;
29+
fn encode_to_key(&self) -> String;
3030
}
3131

3232
pub(crate) trait StorableObjectUpdate<SO: StorableObject> {
@@ -115,7 +115,7 @@ where
115115
let _guard = self.mutation_lock.lock().await;
116116
let should_remove = { self.objects.lock().expect("lock").contains_key(id) };
117117
if should_remove {
118-
let store_key = id.encode_to_hex_str();
118+
let store_key = id.encode_to_key();
119119
KVStore::remove(
120120
&*self.kv_store,
121121
&self.primary_namespace,
@@ -185,7 +185,7 @@ where
185185
}
186186

187187
fn encode_object(object: &SO) -> (String, Vec<u8>) {
188-
(object.id().encode_to_hex_str(), object.encode())
188+
(object.id().encode_to_key(), object.encode())
189189
}
190190

191191
async fn persist_encoded(&self, store_key: String, data: Vec<u8>) -> Result<(), Error> {
@@ -238,7 +238,7 @@ mod tests {
238238
}
239239

240240
impl StorableObjectId for TestObjectId {
241-
fn encode_to_hex_str(&self) -> String {
241+
fn encode_to_key(&self) -> String {
242242
hex_utils::to_string(&self.id)
243243
}
244244
}
@@ -354,7 +354,7 @@ mod tests {
354354
let id = TestObjectId { id: [42u8; 4] };
355355
assert!(data_store.get(&id).is_none());
356356

357-
let store_key = id.encode_to_hex_str();
357+
let store_key = id.encode_to_key();
358358

359359
// Check we start empty.
360360
assert!(KVStore::read(&*store, &primary_namespace, &secondary_namespace, &store_key)

src/payment/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Readable for PaymentDetails {
149149
}
150150

151151
impl StorableObjectId for PaymentId {
152-
fn encode_to_hex_str(&self) -> String {
152+
fn encode_to_key(&self) -> String {
153153
hex_utils::to_string(&self.0)
154154
}
155155
}

0 commit comments

Comments
 (0)