use {
crate::core::{
Ident, Symbol, SymbolPath, SymbolVisibility, Value, Visibility,
},
laburnum::{
Ident as LaburnumIdent,
database::{Partition, PartitionKey},
},
std::{hash::Hash, marker::PhantomData},
};
#[derive(Hash)]
pub struct Symbols<V, I, P, S = SymbolVisibility>(PhantomData<(V, I, P, S)>);
impl<V, I, P, S> Default for Symbols<V, I, P, S> {
fn default() -> Self {
Self(PhantomData)
}
}
impl<V, I, P, S> Clone for Symbols<V, I, P, S> {
fn clone(&self) -> Self {
*self
}
}
impl<V, I, P, S> Copy for Symbols<V, I, P, S> {}
impl<V, I, P, S> std::fmt::Debug for Symbols<V, I, P, S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Symbols").finish()
}
}
impl<V, I, P, S> PartitionKey for Symbols<V, I, P, S>
where
V: Value<I>,
I: Ident,
P: SymbolPath,
S: Visibility,
{
const KEY: LaburnumIdent = LaburnumIdent::new("symbolique::symbols");
}
impl<V, I, P, S> Partition for Symbols<V, I, P, S>
where
V: Value<I>,
I: Ident,
P: SymbolPath,
S: Visibility,
{
type Record = Symbol<V, I, P, S>;
type IndexEntry = (); type SortKey = String;
fn index_entry_from_handle(
_handle: laburnum::database::RecordHandle<Self>,
) -> Self::IndexEntry {
}
}
#[cfg(test)]
mod tests {
use super::*;
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
struct TestPath(String);
impl laburnum::PartitionSortKey for TestPath {
fn is_prefix_of(&self, other: &Self) -> bool {
other.0.starts_with(&self.0)
}
fn resolve(&self, _resolver: &dyn laburnum::SourceResolver) -> String {
self.0.clone()
}
}
#[test]
fn symbols_partition_key() {
use crate::core::{DefaultValue, StringIdent};
let key = Symbols::<DefaultValue, StringIdent, TestPath>::KEY;
assert_eq!(key, laburnum::Ident::new("symbolique::symbols"));
}
#[test]
fn symbols_is_cas_only() {
use crate::core::{DefaultValue, StringIdent};
fn assert_index_entry_is_unit<P: Partition<IndexEntry = ()>>() {}
assert_index_entry_is_unit::<Symbols<DefaultValue, StringIdent, TestPath>>(
);
}
}