elevator_core/components/
position.rs1use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
18pub struct Position {
19 pub(crate) value: f64,
21}
22
23impl Position {
24 #[must_use]
26 pub const fn value(&self) -> f64 {
27 self.value
28 }
29}
30
31impl fmt::Display for Position {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "{:.2}m", self.value)
34 }
35}
36
37impl From<f64> for Position {
38 fn from(value: f64) -> Self {
39 debug_assert!(
40 value.is_finite(),
41 "Position value must be finite, got {value}"
42 );
43 Self { value }
44 }
45}
46
47#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
61pub struct Velocity {
62 pub(crate) value: f64,
64}
65
66impl Velocity {
67 #[must_use]
69 pub const fn value(&self) -> f64 {
70 self.value
71 }
72}
73
74impl fmt::Display for Velocity {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 write!(f, "{:.2}m/s", self.value)
77 }
78}
79
80impl From<f64> for Velocity {
81 fn from(value: f64) -> Self {
82 debug_assert!(
83 value.is_finite(),
84 "Velocity value must be finite, got {value}"
85 );
86 Self { value }
87 }
88}