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
use serde::{Deserialize, Serialize};

pub struct Flight {
    min_height: f32,
    max_height: f32,
}

impl Flight {
    /// Returns minimum flight height (above terrain) of the object.
    pub fn min_height(&self) -> f32 {
        self.min_height
    }

    /// Returns maximum flight height (above terrain) of the object.
    pub fn max_height(&self) -> f32 {
        self.max_height
    }
}

impl TryFrom<FlightSerde> for Flight {
    type Error = anyhow::Error;

    fn try_from(flight_serde: FlightSerde) -> Result<Self, Self::Error> {
        Ok(Self {
            min_height: flight_serde.min_height,
            max_height: flight_serde.max_height,
        })
    }
}

#[derive(Serialize, Deserialize)]
pub(crate) struct FlightSerde {
    min_height: f32,
    max_height: f32,
}