Remove push/pop_local_changes from FileProvider trait
[hiphop-php.git] / hphp / hack / src / rupro / datastore / datastore.rs
blob4329cd21d209350b63d67b5278bfcf68da81c66f
1 // Copyright (c) Meta Platforms, Inc. and affiliates.
2 //
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
6 mod changes_store;
7 mod delta_store;
8 mod empty;
9 mod non_evicting;
11 use anyhow::Result;
12 use std::fmt::Debug;
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
40 /// `DeltaStore`).
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>> {
47         Store::get(self, key)
48     }