1 // Copyright (c) Meta Platforms, Inc. and affiliates.
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
14 pub use changes_store::ChangesStore;
15 pub use delta_store::DeltaStore;
16 pub use empty::EmptyStore;
17 pub use non_evicting::{NonEvictingLocalStore, NonEvictingStore};
19 /// A threadsafe datastore, intended for global decl storage. The key type is
20 /// intended to be a `Symbol` or tuple of `Symbol`s, and the value type is
21 /// intended to be a ref-counted pointer (like `Arc` or `Hc`).
22 pub trait Store<K: Copy, V>: Debug + Send + Sync {
23 fn get(&self, key: K) -> Result<Option<V>>;
24 fn insert(&self, key: K, val: V) -> Result<()>;
25 fn remove_batch(&self, keys: &mut dyn Iterator<Item = K>) -> Result<()>;
28 /// A thread-local datastore, intended for decl caching in typechecker workers.
29 /// The key type is intended to be a `Symbol` or tuple of `Symbol`s, and the
30 /// value type is intended to be a ref-counted pointer (like `Rc`).
31 pub trait LocalStore<K: Copy, V>: Debug {
32 fn get(&self, key: K) -> Option<V>;
33 fn insert(&mut self, key: K, val: V);
34 fn remove_batch(&mut self, keys: &mut dyn Iterator<Item = K>);
37 /// A readonly threadsafe datastore, intended to model readonly data sources
38 /// (like the filesystem in file_provider, or the naming SQLite database in
39 /// naming_provider) in terms of `datastore` traits (for purposes like
41 pub trait ReadonlyStore<K: Copy, V>: Send + Sync {
42 fn get(&self, key: K) -> Result<Option<V>>;
45 impl<T: Store<K, V>, K: Copy, V> ReadonlyStore<K, V> for T {
46 fn get(&self, key: K) -> Result<Option<V>> {