Skip to content

Commit 2cfba4c

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): add trait for encoding keys for indexed types in event cache store
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
1 parent 1bce2af commit 2cfba4c

File tree

1 file changed

+21
-0
lines changed
  • crates/matrix-sdk-indexeddb/src/event_cache_store/serializer

1 file changed

+21
-0
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/traits.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,24 @@ pub trait Indexed: Sized {
4242
serializer: &IndexeddbSerializer,
4343
) -> Result<Self, Self::Error>;
4444
}
45+
46+
/// A trait for encoding types which will be used as keys in IndexedDB.
47+
///
48+
/// Each implementation represents a key on an [`Indexed`] type.
49+
pub trait IndexedKey<T: Indexed> {
50+
/// Any extra data used to construct the key.
51+
type KeyComponents;
52+
53+
/// Encodes the key components into a type that can be used as a key in
54+
/// IndexedDB.
55+
///
56+
/// Note that this function takes an [`IndexeddbSerializer`] as an
57+
/// argument, which provides the necessary context for encryption and
58+
/// decryption, in the case that certain components of the key must be
59+
/// encrypted before storage.
60+
fn encode(
61+
room_id: &RoomId,
62+
components: &Self::KeyComponents,
63+
serializer: &IndexeddbSerializer,
64+
) -> Self;
65+
}

0 commit comments

Comments
 (0)