use willow_data_model::prelude as wdm;
use crate::prelude::*;
pub trait Coordinatelike: Keylike + wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> {
fn timestamp(&self) -> Timestamp;
}
impl<T> Coordinatelike for T
where
T: Keylike + wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> + ?Sized,
{
fn timestamp(&self) -> Timestamp {
self.wdm_timestamp()
}
}
impl wdm::Keylike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Path, Timestamp) {
fn wdm_subspace_id(&self) -> &SubspaceId {
&self.0
}
fn wdm_path(&self) -> &wdm::Path<MCL, MCC, MPL> {
(&self.1).into()
}
}
impl wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Path, Timestamp) {
fn wdm_timestamp(&self) -> Timestamp {
self.2
}
}
impl wdm::Keylike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Timestamp, Path) {
fn wdm_subspace_id(&self) -> &SubspaceId {
&self.0
}
fn wdm_path(&self) -> &wdm::Path<MCL, MCC, MPL> {
(&self.2).into()
}
}
impl wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Timestamp, Path) {
fn wdm_timestamp(&self) -> Timestamp {
self.1
}
}
impl wdm::Keylike<MCL, MCC, MPL, SubspaceId> for (Path, SubspaceId, Timestamp) {
fn wdm_subspace_id(&self) -> &SubspaceId {
&self.1
}
fn wdm_path(&self) -> &wdm::Path<MCL, MCC, MPL> {
(&self.0).into()
}
}
impl wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Path, SubspaceId, Timestamp) {
fn wdm_timestamp(&self) -> Timestamp {
self.2
}
}
impl wdm::Keylike<MCL, MCC, MPL, SubspaceId> for (Path, Timestamp, SubspaceId) {
fn wdm_subspace_id(&self) -> &SubspaceId {
&self.2
}
fn wdm_path(&self) -> &wdm::Path<MCL, MCC, MPL> {
(&self.0).into()
}
}
impl wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Path, Timestamp, SubspaceId) {
fn wdm_timestamp(&self) -> Timestamp {
self.1
}
}
impl wdm::Keylike<MCL, MCC, MPL, SubspaceId> for (Timestamp, SubspaceId, Path) {
fn wdm_subspace_id(&self) -> &SubspaceId {
&self.1
}
fn wdm_path(&self) -> &wdm::Path<MCL, MCC, MPL> {
(&self.2).into()
}
}
impl wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Timestamp, SubspaceId, Path) {
fn wdm_timestamp(&self) -> Timestamp {
self.0
}
}
impl wdm::Keylike<MCL, MCC, MPL, SubspaceId> for (Timestamp, Path, SubspaceId) {
fn wdm_subspace_id(&self) -> &SubspaceId {
&self.2
}
fn wdm_path(&self) -> &wdm::Path<MCL, MCC, MPL> {
(&self.1).into()
}
}
impl wdm::Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Timestamp, Path, SubspaceId) {
fn wdm_timestamp(&self) -> Timestamp {
self.0
}
}
pub trait CoordinatelikeExt: Coordinatelike + KeylikeExt {
fn coordinate_eq<OtherCoordinate>(&self, other: &OtherCoordinate) -> bool
where
OtherCoordinate: Coordinatelike,
{
self.key_eq(other) && self.timestamp() == other.timestamp()
}
fn coordinate_ne<OtherCoordinate>(&self, other: &OtherCoordinate) -> bool
where
OtherCoordinate: Coordinatelike,
{
self.key_ne(other) || self.timestamp() != other.timestamp()
}
fn is_in<G>(&self, grouping: &G) -> bool
where
G: Grouping,
{
grouping.includes(self)
}
fn is_in_intersection<G>(&self, grouping1: &G, grouping2: &G) -> bool
where
G: Grouping,
{
grouping1.includes_in_intersection(grouping2, self)
}
}
impl<T> CoordinatelikeExt for T where T: Coordinatelike + ?Sized {}