foyer_common/
code.rs

1// Copyright 2025 foyer Project Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::hash::{BuildHasher, Hash};
16
17use serde::{de::DeserializeOwned, Serialize};
18
19/// Key trait for the in-memory cache.
20pub trait Key: Send + Sync + 'static + Hash + Eq {}
21/// Value trait for the in-memory cache.
22pub trait Value: Send + Sync + 'static {}
23
24impl<T: Send + Sync + 'static + std::hash::Hash + Eq> Key for T {}
25impl<T: Send + Sync + 'static> Value for T {}
26
27/// Key trait for the disk cache.
28pub trait StorageKey: Key + Serialize + DeserializeOwned {}
29impl<T> StorageKey for T where T: Key + Serialize + DeserializeOwned {}
30
31/// Value trait for the disk cache.
32pub trait StorageValue: Value + 'static + Serialize + DeserializeOwned {}
33impl<T> StorageValue for T where T: Value + Serialize + DeserializeOwned {}
34
35/// Hash builder trait.
36pub trait HashBuilder: BuildHasher + Send + Sync + 'static {}
37impl<T> HashBuilder for T where T: BuildHasher + Send + Sync + 'static {}