2025-08-27 23:59:19 +02:00
|
|
|
use std::fmt;
|
|
|
|
|
|
2025-09-11 02:49:14 +02:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
2025-08-27 23:59:19 +02:00
|
|
|
use super::translator::PrintableWithTranslator;
|
|
|
|
|
|
|
|
|
|
pub type IdType = u32;
|
|
|
|
|
|
2025-09-05 13:13:35 +02:00
|
|
|
impl PrintableWithTranslator for IdType {
|
2025-09-07 17:55:53 +02:00
|
|
|
fn print(
|
|
|
|
|
&self,
|
|
|
|
|
f: &mut fmt::Formatter,
|
|
|
|
|
translator: &super::translator::Translator,
|
2025-09-05 13:13:35 +02:00
|
|
|
) -> fmt::Result {
|
2025-09-07 17:55:53 +02:00
|
|
|
write!(
|
|
|
|
|
f,
|
|
|
|
|
"{}",
|
|
|
|
|
translator.decode(*self).unwrap_or("Missing".into())
|
|
|
|
|
)
|
2025-09-05 13:13:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2025-09-10 22:41:40 +02:00
|
|
|
#[derive(
|
|
|
|
|
Clone,
|
|
|
|
|
Copy,
|
|
|
|
|
Debug,
|
|
|
|
|
PartialEq,
|
|
|
|
|
Eq,
|
|
|
|
|
PartialOrd,
|
|
|
|
|
Ord,
|
|
|
|
|
Hash,
|
|
|
|
|
Serialize,
|
|
|
|
|
Deserialize,
|
|
|
|
|
)]
|
2025-08-27 23:59:19 +02:00
|
|
|
pub enum IdState {
|
|
|
|
|
Positive,
|
2025-09-07 17:55:53 +02:00
|
|
|
Negative,
|
2025-08-27 23:59:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for IdState {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2025-09-07 17:55:53 +02:00
|
|
|
match self {
|
2025-09-11 02:49:14 +02:00
|
|
|
| Self::Positive => write!(f, "+"),
|
|
|
|
|
| Self::Negative => write!(f, "-"),
|
2025-09-07 17:55:53 +02:00
|
|
|
}
|
2025-08-27 23:59:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::ops::Not for IdState {
|
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
|
|
fn not(self) -> Self::Output {
|
2025-09-07 17:55:53 +02:00
|
|
|
match self {
|
2025-09-11 02:49:14 +02:00
|
|
|
| Self::Positive => Self::Negative,
|
|
|
|
|
| Self::Negative => Self::Positive,
|
2025-09-07 17:55:53 +02:00
|
|
|
}
|
2025-08-27 23:59:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 22:41:40 +02:00
|
|
|
#[derive(
|
|
|
|
|
Clone,
|
|
|
|
|
Copy,
|
|
|
|
|
Debug,
|
|
|
|
|
PartialEq,
|
|
|
|
|
Eq,
|
|
|
|
|
PartialOrd,
|
|
|
|
|
Ord,
|
|
|
|
|
Hash,
|
|
|
|
|
Serialize,
|
|
|
|
|
Deserialize,
|
|
|
|
|
)]
|
2025-08-27 23:59:19 +02:00
|
|
|
pub struct PositiveType {
|
2025-09-11 02:49:14 +02:00
|
|
|
pub id: IdType,
|
2025-09-07 17:55:53 +02:00
|
|
|
pub state: IdState,
|
2025-08-27 23:59:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PrintableWithTranslator for PositiveType {
|
2025-09-07 17:55:53 +02:00
|
|
|
fn print(
|
|
|
|
|
&self,
|
|
|
|
|
f: &mut fmt::Formatter,
|
|
|
|
|
translator: &super::translator::Translator,
|
|
|
|
|
) -> std::fmt::Result {
|
|
|
|
|
write!(
|
|
|
|
|
f,
|
|
|
|
|
"{}{}",
|
|
|
|
|
self.state,
|
|
|
|
|
translator.decode(self.id).unwrap_or("Missing".into())
|
|
|
|
|
)
|
2025-08-27 23:59:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-08 19:04:26 +02:00
|
|
|
|
|
|
|
|
impl From<(IdType, IdState)> for PositiveType {
|
|
|
|
|
fn from(value: (IdType, IdState)) -> Self {
|
2025-09-10 22:41:40 +02:00
|
|
|
Self {
|
2025-09-11 02:49:14 +02:00
|
|
|
id: value.0,
|
2025-09-10 22:41:40 +02:00
|
|
|
state: value.1,
|
|
|
|
|
}
|
2025-09-08 19:04:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<(&IdType, &IdState)> for PositiveType {
|
|
|
|
|
fn from(value: (&IdType, &IdState)) -> Self {
|
2025-09-10 22:41:40 +02:00
|
|
|
Self {
|
2025-09-11 02:49:14 +02:00
|
|
|
id: *value.0,
|
2025-09-10 22:41:40 +02:00
|
|
|
state: *value.1,
|
|
|
|
|
}
|
2025-09-08 19:04:26 +02:00
|
|
|
}
|
|
|
|
|
}
|