1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#[cfg(feature = "pylib")]
use pyo3::prelude::*;
use std::fmt::Display;
#[cfg_attr(feature = "pylib", pyclass(module = "bufkit_data"))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct StationNumber {
num: u32,
}
impl From<u32> for StationNumber {
fn from(val: u32) -> Self {
StationNumber { num: val }
}
}
impl Into<u32> for StationNumber {
fn into(self) -> u32 {
self.num
}
}
impl Into<i64> for StationNumber {
fn into(self) -> i64 {
i64::from(self.num)
}
}
impl Display for StationNumber {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(formatter, "{}", self.num)
}
}
impl StationNumber {
pub fn is_valid(self) -> bool {
self.num > 0
}
pub const fn new(num: u32) -> Self {
StationNumber { num }
}
}
#[cfg(feature = "pylib")]
#[cfg_attr(feature = "pylib", pymethods)]
impl StationNumber {
fn __repr__(&self) -> PyResult<String> {
Ok(format!("bufkit_data::StationNumber({})", self.num))
}
#[new]
fn py_new(num: u32) -> Self {
Self::new(num)
}
#[getter]
fn get_as_number(&self) -> u32 {
self.num
}
}