f1_api/types.rs
1//! Collection of auxiliary types that are used throughout the crate
2
3use derive_new::new;
4use getset::CopyGetters;
5
6/// Flags shown in formula racing
7///
8/// Flags are an essential tool to communicate the status of a race to the drivers on track. A green
9/// flag signals the race start or restart, while a yellow flag warns of hazards on track. The red
10/// flag aborts a race or session. The blue flag signals that a faster car is approaching from
11/// behind.
12#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
13pub enum Flag {
14 Invalid,
15 None,
16 Green,
17 Blue,
18 Yellow,
19 Red,
20}
21
22impl Default for Flag {
23 fn default() -> Self {
24 Flag::None
25 }
26}
27
28/// Reference to a vehicle in a packet
29///
30/// In Formula 1, a maximum of 20 cars can participate in any session. The modern F1 games use this
31/// rule to use arrays with a static size of 20 whenever they publish data about all vehicles in a
32/// session. Data in those arrays is referenced using an unsigned byte. By defining a type alias for
33/// the indices, their usage can be checked by the Rust compiler.
34pub type VehicleIndex = u8;
35
36/// Property on each corner of a car
37///
38/// The F1 games publish telemetry data and setup parameters that describe each corner of a car. For
39/// example, the suspension settings or tyre pressures are a set of four numbers, one for each
40/// corner of the car. These properties can be expressed by the `Corner` type.
41///
42/// # Examples
43///
44/// ```
45/// use f1_api::types::CornerProperty;
46///
47/// let suspension_position = CornerProperty::new(1.0, 0.9, 1.1, 1.0);
48/// ```
49#[derive(new, Debug, CopyGetters, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash, Default)]
50pub struct CornerProperty<T>
51where
52 T: Copy,
53{
54 /// Returns the value of the property at the front left.
55 #[getset(get_copy = "pub")]
56 front_left: T,
57
58 /// Returns the value of the property at the front right.
59 #[getset(get_copy = "pub")]
60 front_right: T,
61
62 /// Returns the value of the property at the rear left.
63 #[getset(get_copy = "pub")]
64 rear_left: T,
65
66 /// Returns the value of the property at the rear right.
67 #[getset(get_copy = "pub")]
68 rear_right: T,
69}
70
71/// Property in a three-dimensional world
72///
73/// The F1 games publish data that places objects in a three dimensional world. Examples include the
74/// position of a car, its velocity, or the direction of its motion.
75///
76/// # Examples
77///
78/// ```
79/// use f1_api::types::Property3D;
80///
81/// let g_forces = Property3D::new(1.0, 1.3, 0.9);
82/// ```
83#[derive(new, Debug, CopyGetters, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash, Default)]
84pub struct Property3D<T>
85where
86 T: Copy,
87{
88 /// Returns the component on the X axis of the three-dimensional property.
89 #[getset(get_copy = "pub")]
90 x: T,
91
92 /// Returns the component on the Y axis of the three-dimensional property.
93 #[getset(get_copy = "pub")]
94 y: T,
95
96 /// Returns the component on the Z axis of the three-dimensional property.
97 #[getset(get_copy = "pub")]
98 z: T,
99}