protoflight 0.1.3

Protoflight flight controller.
use super::RangefinderType;

#[cfg(feature = "serde")]
use {
    postcard::experimental::max_size::MaxSize,
    sequential_storage::map::PostcardValue,
    serde::{Deserialize, Serialize},
};

#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize, MaxSize))]
pub struct RangefinderConfig {
    pub hardware: RangefinderType,
}

#[cfg(feature = "serde")]
impl PostcardValue<'_> for RangefinderConfig {}

impl Default for RangefinderConfig {
    fn default() -> Self {
        Self::new()
    }
}

#[allow(unused)]
impl RangefinderConfig {
    pub const fn new() -> Self {
        Self { hardware: RangefinderType::NoRangefinder }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn _is_normal<T: Sized + Send + Sync + Unpin>() {}
    fn is_full<T: Sized + Send + Sync + Unpin + Copy + Clone + Default + PartialEq>() {}
    #[cfg(feature = "serde")]
    fn is_config<T: Serialize + MaxSize + for<'a> Deserialize<'a> + for<'a> PostcardValue<'a>>() {}

    #[test]
    fn normal_types() {
        is_full::<RangefinderConfig>();
        #[cfg(feature = "serde")]
        is_config::<RangefinderConfig>();
    }
}