use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(transparent)]
pub struct TrackId(pub u64);
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(transparent)]
pub struct PatternId(pub u64);
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(transparent)]
pub struct PlacementId(pub u64);
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(transparent)]
pub struct ParamId(pub u64);
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(transparent)]
pub struct BusId(pub u64);
impl TrackId {
pub fn get(self) -> u64 {
self.0
}
}
impl PatternId {
pub fn get(self) -> u64 {
self.0
}
}
impl PlacementId {
pub fn get(self) -> u64 {
self.0
}
}
impl ParamId {
pub fn get(self) -> u64 {
self.0
}
}
impl BusId {
pub fn get(self) -> u64 {
self.0
}
}
impl From<u64> for TrackId {
fn from(n: u64) -> Self {
TrackId(n)
}
}
impl From<u64> for PatternId {
fn from(n: u64) -> Self {
PatternId(n)
}
}
impl From<u64> for PlacementId {
fn from(n: u64) -> Self {
PlacementId(n)
}
}
impl From<u64> for ParamId {
fn from(n: u64) -> Self {
ParamId(n)
}
}
impl From<u64> for BusId {
fn from(n: u64) -> Self {
BusId(n)
}
}
impl std::fmt::Display for TrackId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::fmt::Display for PatternId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::fmt::Display for PlacementId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::fmt::Display for ParamId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::fmt::Display for BusId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serde_round_trip_is_the_bare_number() {
assert_eq!(serde_json::to_string(&TrackId::from(3)).unwrap(), "3");
assert_eq!(serde_json::to_string(&BusId::from(9)).unwrap(), "9");
let id: TrackId = serde_json::from_str("3").unwrap();
assert_eq!(id, TrackId(3));
assert_eq!(id.get(), 3);
}
#[test]
fn display_is_the_bare_number() {
assert_eq!(TrackId(3).to_string(), "3");
assert_eq!(PlacementId(17).to_string(), "17");
}
}