use {
crate::{
core::{Ident, SymbolPath, Value, Visibility},
partitions::{
records::ResolutionEntry, resolution::SymbolResolution, symbols::Symbols,
},
},
laburnum::database::{
HasPartition, RecordRef,
query::QueryClient,
storage::Partitions,
},
};
pub trait ResolutionReadExt<P: Partitions> {
fn resolution_at_path<V, I, Path, S>(
&self,
sort_key: &Path,
) -> Option<ResolutionEntry<V, I, Path, S>>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
S: Visibility,
P::Stores: HasPartition<SymbolResolution<V, I, Path, S>>;
fn resolutions_with_prefix<V, I, Path, S>(
&self,
prefix: &Path,
) -> Vec<(Path, ResolutionEntry<V, I, Path, S>)>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
S: Visibility,
P::Stores: HasPartition<SymbolResolution<V, I, Path, S>>;
fn resolve_resolution_target<V, I, Path, S>(
&self,
entry: &ResolutionEntry<V, I, Path, S>,
) -> Option<RecordRef<'_, Symbols<V, I, Path, S>>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores: HasPartition<Symbols<V, I, Path, S>>;
}
impl<P: Partitions> ResolutionReadExt<P> for QueryClient<P> {
fn resolution_at_path<V, I, Path, S>(
&self,
sort_key: &Path,
) -> Option<ResolutionEntry<V, I, Path, S>>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
S: Visibility,
P::Stores: HasPartition<SymbolResolution<V, I, Path, S>>,
{
self.index_get::<SymbolResolution<V, I, Path, S>>(sort_key)
}
fn resolutions_with_prefix<V, I, Path, S>(
&self,
prefix: &Path,
) -> Vec<(Path, ResolutionEntry<V, I, Path, S>)>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
S: Visibility,
P::Stores: HasPartition<SymbolResolution<V, I, Path, S>>,
{
self.index_range::<SymbolResolution<V, I, Path, S>>(prefix)
}
fn resolve_resolution_target<V, I, Path, S>(
&self,
entry: &ResolutionEntry<V, I, Path, S>,
) -> Option<RecordRef<'_, Symbols<V, I, Path, S>>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores: HasPartition<Symbols<V, I, Path, S>>,
{
let handle = entry.target.handle()?;
self.get::<Symbols<V, I, Path, S>>(handle.content_hash())
}
}