use crate::{
Ident,
database::{
DynPartition,
PartitionKey,
},
};
pub struct Workspace;
impl PartitionKey for Workspace {
const KEY: Ident = Ident::new("laburnum::workspace");
}
impl DynPartition for Workspace {
type DynSortKey = WorkspaceSortKey;
type RecordConstraint = dyn WorkspaceRecord;
}
impl<R: WorkspaceRecord + crate::record::Record>
crate::database::DynPartitionRecord<Workspace> for R
{
}
#[derive(Debug, Clone)]
pub enum WorkspaceSortKey {
Config,
All,
}
impl std::fmt::Display for WorkspaceSortKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
| WorkspaceSortKey::Config => write!(f, "config"),
| WorkspaceSortKey::All => Ok(()),
}
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
enum WsToken {
Config,
}
impl WorkspaceSortKey {
fn tokens(&self) -> Vec<WsToken> {
match self {
| WorkspaceSortKey::Config => vec![WsToken::Config],
| WorkspaceSortKey::All => Vec::new(),
}
}
}
impl PartialEq for WorkspaceSortKey {
fn eq(&self, other: &Self) -> bool {
self.tokens() == other.tokens()
}
}
impl Eq for WorkspaceSortKey {}
impl std::hash::Hash for WorkspaceSortKey {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.tokens().hash(state);
}
}
impl PartialOrd for WorkspaceSortKey {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for WorkspaceSortKey {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.tokens().cmp(&other.tokens())
}
}
impl crate::database::PartitionSortKey for WorkspaceSortKey {
fn is_prefix_of(&self, other: &Self) -> bool {
other.tokens().starts_with(&self.tokens())
}
fn resolve(&self, _resolver: &dyn crate::SourceResolver) -> String {
self.to_string()
}
}
pub trait WorkspaceRecord: Send + Sync + std::fmt::Debug {}