Applying parameterization concepts
We have explored the concepts of generics and parameterization. Let's scan through the project to see if any concepts would be appropriate to use.
Parameterizing data
Parametric data allows us to declare only the minimal amount of semantic information required. Instead of specifying a type, we can specify a generic parameter having a trait. Let's start by looking at physics.rs
type declarations:
#[derive(Clone,Serialize,Deserialize,Debug)] pub enum MotorInput { Up { voltage: f64 }, Down { voltage: f64 } } #[derive(Clone,Serialize,Deserialize,Debug)] pub struct ElevatorSpecification { pub floor_count: u64, pub floor_height: f64,
pub carriage_weight: f64 } #[derive(Clone,Serialize,Deserialize,Debug)] pub struct ElevatorState { pub timestamp: f64, pub location: f64, pub velocity: f64, pub acceleration: f64, pub motor_input: MotorInput } pub type FloorRequests = Vec<u64>;
If we remember, where we used physics.rs
when we designed...