use intmap::IntKey;
#[cfg(any(test, feature = "testactivities"))]
use uuid::Uuid;
use std::{
fmt::{Debug, Display},
hash::Hash,
};
#[derive(Clone, Copy, Ord, Eq, PartialEq, PartialOrd)]
#[cfg(not(any(test, feature = "testactivities")))]
pub struct Activity {
pub id: usize,
}
#[derive(Clone, Copy, Eq)]
#[cfg(any(test, feature = "testactivities"))]
pub struct Activity {
pub id: usize,
pub activity_key_uuid: Uuid, }
impl PartialEq<usize> for Activity {
fn eq(&self, other: &usize) -> bool {
&self.id == other
}
}
impl Hash for Activity {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
impl Display for Activity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ac{}", self.id)
}
}
impl Debug for Activity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ac{}", self.id)
}
}
impl PartialOrd<usize> for Activity {
fn partial_cmp(&self, other: &usize) -> Option<std::cmp::Ordering> {
self.id.partial_cmp(other)
}
}
impl IntKey for Activity {
type Int = usize;
const PRIME: Self::Int = usize::PRIME;
fn into_int(self) -> Self::Int {
self.id
}
}
#[cfg(any(test, feature = "testactivities"))]
impl PartialEq for Activity {
fn eq(&self, other: &Self) -> bool {
assert!(
self.activity_key_uuid == other.activity_key_uuid,
"cannot compare activities of different activity keys"
);
self.id == other.id
}
}
#[cfg(any(test, feature = "testactivities"))]
impl Ord for Activity {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
assert!(
self.activity_key_uuid == other.activity_key_uuid,
"cannot compare activities of different activity keys"
);
self.id.cmp(&other.id)
}
}
#[cfg(any(test, feature = "testactivities"))]
impl PartialOrd for Activity {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
assert!(
self.activity_key_uuid == other.activity_key_uuid,
"cannot compare activities of different activity keys"
);
self.id.partial_cmp(&other.id)
}
}