1use std::panic::RefUnwindSafe;
2
3pub trait CacheKey: RefUnwindSafe {
5 fn hash_bytes(&self) -> &[u8];
8}
9
10impl CacheKey for u32 {
11 fn hash_bytes(&self) -> &[u8] {
12 &bytemuck::bytes_of(&*self)
13 }
14}
15
16impl CacheKey for i32 {
17 fn hash_bytes(&self) -> &[u8] {
18 &bytemuck::bytes_of(&*self)
19 }
20}
21
22impl CacheKey for &[u8] {
23 fn hash_bytes(&self) -> &[u8] {
24 self
25 }
26}
27
28impl CacheKey for Vec<u8> {
29 fn hash_bytes(&self) -> &[u8] {
30 &self
31 }
32}
33
34impl CacheKey for Vec<u32> {
35 fn hash_bytes(&self) -> &[u8] {
36 bytemuck::cast_slice(&self)
37 }
38}
39
40impl CacheKey for &str {
41 fn hash_bytes(&self) -> &[u8] {
42 self.as_bytes()
44 }
45}