use {
super::records::SymbolEntry,
crate::core::{Ident, SymbolPath, SymbolSortKey, Value},
laburnum::{
Ident as LaburnumIdent,
database::{Partition, PartitionKey},
},
std::{hash::Hash, marker::PhantomData},
};
#[derive(Hash)]
pub struct MergedSymbols<V, I, P>(PhantomData<(V, I, P)>);
impl<V, I, P> Default for MergedSymbols<V, I, P> {
fn default() -> Self {
Self(PhantomData)
}
}
impl<V, I, P> Clone for MergedSymbols<V, I, P> {
fn clone(&self) -> Self {
*self
}
}
impl<V, I, P> Copy for MergedSymbols<V, I, P> {}
impl<V, I, P> std::fmt::Debug for MergedSymbols<V, I, P> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MergedSymbols").finish()
}
}
impl<V, I, P> PartitionKey for MergedSymbols<V, I, P>
where
V: Value<I>,
I: Ident,
P: SymbolPath,
{
const KEY: LaburnumIdent = LaburnumIdent::new("symbolique::merged_symbols");
}
impl<V, I, P> Partition for MergedSymbols<V, I, P>
where
V: Value<I>,
I: Ident,
P: SymbolPath,
{
type Record = (); type IndexEntry = SymbolEntry<V, I, P>;
type SortKey = SymbolSortKey;
}
#[derive(Hash)]
pub struct MergedSymbolIndex<V, I, P>(PhantomData<(V, I, P)>);
impl<V, I, P> Default for MergedSymbolIndex<V, I, P> {
fn default() -> Self {
Self(PhantomData)
}
}
impl<V, I, P> Clone for MergedSymbolIndex<V, I, P> {
fn clone(&self) -> Self {
*self
}
}
impl<V, I, P> Copy for MergedSymbolIndex<V, I, P> {}
impl<V, I, P> std::fmt::Debug for MergedSymbolIndex<V, I, P> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MergedSymbolIndex").finish()
}
}
impl<V, I, P> PartitionKey for MergedSymbolIndex<V, I, P>
where
V: Value<I>,
I: Ident,
P: SymbolPath,
{
const KEY: LaburnumIdent =
LaburnumIdent::new("symbolique::merged_symbol_index");
}
impl<V, I, P> Partition for MergedSymbolIndex<V, I, P>
where
V: Value<I>,
I: Ident,
P: SymbolPath,
{
type Record = (); type IndexEntry = SymbolEntry<V, I, P>;
type SortKey = SymbolSortKey;
}
#[cfg(test)]
mod tests {
use super::*;
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
struct TestPath(String);
impl crate::core::SymbolPath for TestPath {
fn sort_key(&self) -> String {
self.0.clone()
}
}
#[test]
fn merged_symbols_partition_key() {
use crate::core::{DefaultValue, StringIdent};
let key = MergedSymbols::<DefaultValue, StringIdent, TestPath>::KEY;
let key2 = MergedSymbolIndex::<DefaultValue, StringIdent, TestPath>::KEY;
assert_ne!(key, key2);
}
#[test]
fn merged_symbols_is_index_only() {
use crate::core::{DefaultValue, StringIdent};
fn assert_record_is_unit<P: Partition<Record = ()>>() {}
assert_record_is_unit::<MergedSymbols<DefaultValue, StringIdent, TestPath>>(
);
}
}