use {
crate::{
core::{Ident, SymbolPath, Value},
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>(
&self,
sort_key: &str,
) -> Option<ResolutionEntry<V, I, Path>>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
P::Stores: HasPartition<SymbolResolution<V, I, Path>>;
fn resolutions_with_prefix<V, I, Path>(
&self,
prefix: &str,
) -> Vec<(String, ResolutionEntry<V, I, Path>)>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
P::Stores: HasPartition<SymbolResolution<V, I, Path>>;
fn resolve_resolution_target<V, I, Path>(
&self,
entry: &ResolutionEntry<V, I, Path>,
) -> Option<RecordRef<'_, Symbols<V, I, Path>>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
P::Stores: HasPartition<Symbols<V, I, Path>>;
}
impl<P: Partitions> ResolutionReadExt<P> for QueryClient<P> {
fn resolution_at_path<V, I, Path>(
&self,
sort_key: &str,
) -> Option<ResolutionEntry<V, I, Path>>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
P::Stores: HasPartition<SymbolResolution<V, I, Path>>,
{
self.index_get::<SymbolResolution<V, I, Path>>(sort_key)
}
fn resolutions_with_prefix<V, I, Path>(
&self,
prefix: &str,
) -> Vec<(String, ResolutionEntry<V, I, Path>)>
where
V: Value<I>,
I: Ident,
Path: SymbolPath,
P::Stores: HasPartition<SymbolResolution<V, I, Path>>,
{
self.index_range::<SymbolResolution<V, I, Path>>(prefix)
}
fn resolve_resolution_target<V, I, Path>(
&self,
entry: &ResolutionEntry<V, I, Path>,
) -> Option<RecordRef<'_, Symbols<V, I, Path>>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
P::Stores: HasPartition<Symbols<V, I, Path>>,
{
self.get::<Symbols<V, I, Path>>(entry.target.content_hash())
}
}