use crate::database::{DynPartition, PartitionKey};
pub struct Workspace;
impl PartitionKey for Workspace {
const KEY: crate::SpannedIdent = crate::partitions::known_keys::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 bluegum::Bluegum for WorkspaceSortKey {
fn node(&self, b: &mut bluegum::Builder) {
b.name("WorkspaceSortKey");
}
}
impl bluegum::BluegumWithState<dyn crate::SourceResolver> for WorkspaceSortKey {
fn node_with_state(
&self,
b: &mut bluegum::Builder,
resolver: &(dyn crate::SourceResolver + 'static),
) {
b.name("WorkspaceSortKey")
.alt(crate::database::PartitionSortKey::resolve(self, resolver));
}
}
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 {}