Files
ReactionSystems/src/rsprocess/element.rs

70 lines
1.6 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
2025-08-27 23:59:19 +02:00
use std::fmt;
use super::translator::PrintableWithTranslator;
pub type IdType = u32;
impl PrintableWithTranslator for IdType {
fn print(
&self,
f: &mut fmt::Formatter,
translator: &super::translator::Translator,
) -> fmt::Result {
write!(
f,
"{}",
translator.decode(*self).unwrap_or("Missing".into())
)
}
}
// -----------------------------------------------------------------------------
2025-08-27 23:59:19 +02:00
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum IdState {
Positive,
Negative,
2025-08-27 23:59:19 +02:00
}
impl fmt::Display for IdState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Positive => write!(f, "+"),
Self::Negative => write!(f, "-"),
}
2025-08-27 23:59:19 +02:00
}
}
impl std::ops::Not for IdState {
type Output = Self;
fn not(self) -> Self::Output {
match self {
Self::Positive => Self::Negative,
Self::Negative => Self::Positive,
}
2025-08-27 23:59:19 +02:00
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct PositiveType {
pub id: IdType,
pub state: IdState,
2025-08-27 23:59:19 +02:00
}
impl PrintableWithTranslator for PositiveType {
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
}
}