mavinspect 0.1.0-alpha2

MAVInspect is a CLI tool and a library to parse and inspect MAVLink protocol XML definitions
Documentation
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use crate::proto::mavlink_messages_v1 as proto;

/// [`super::EnumEntry`] `MAV_CMD` flags.
///
/// Contains flags like `hasLocation` or `isDestination`.
///
/// Makes sense only in the context of MAVLink command enum (`MAV_CMD`).
///
/// See: MAVLink [command details](https://mavlink.io/en/guide/xml_schema.html#MAV_CMD) in XML
/// schema docs.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EnumEntryMavCmdFlags {
    has_location: Option<bool>,
    is_destination: Option<bool>,
    mission_only: Option<bool>,
}

impl EnumEntryMavCmdFlags {
    /// Default constructor.
    ///
    /// # Arguments
    ///
    /// * `has_location` - Has location flag. See [`EnumEntryMavCmdFlags::has_location`].
    /// * `is_destination` - Is destination flag. See [`EnumEntryMavCmdFlags::is_destination`].
    /// * `mission_only` - Mission only flag. See [`EnumEntryMavCmdFlags::mission_only`].
    pub fn new(
        has_location: Option<bool>,
        is_destination: Option<bool>,
        mission_only: Option<bool>,
    ) -> Self {
        Self {
            has_location,
            is_destination,
            mission_only,
        }
    }

    /// Converts to Protobuf [`proto::EnumEntryMavCmdFlags`].
    pub fn to_proto(&self) -> proto::EnumEntryMavCmdFlags {
        proto::EnumEntryMavCmdFlags {
            has_location: self.has_location,
            is_destination: self.is_destination,
            mission_only: self.mission_only,
        }
    }

    /// Constructs from Protobuf [`proto::EnumEntryMavCmdFlags`].
    pub fn from_proto(proto: proto::EnumEntryMavCmdFlags) -> Self {
        Self {
            has_location: proto.has_location,
            is_destination: proto.is_destination,
            mission_only: proto.mission_only,
        }
    }

    /// Has location.
    ///
    /// A boolean (default `true`) that provides a hint to a GCS that the entry should be displayed as a "standalone"
    /// location - rather than as a destination on the flight path. Apply for MAV_CMDs that contain lat/lon/alt location
    /// information in param 5, 6, and 7 values but which are not on the vehicle path.
    ///
    /// See: MAVLink [command details](https://mavlink.io/en/guide/xml_schema.html#MAV_CMD) in XML schema docs.
    pub fn has_location(&self) -> &Option<bool> {
        &self.has_location
    }

    /// Is destination.
    ///
    /// A boolean (default `true`) that provides a hint to a GCS that the entry is a location that should be displayed as
    /// a point on the flight path. Apply for MAV_CMD that contain lat/lon/alt location information in their param 5, 6,
    /// and 7 values, and that set a path/destination.
    ///
    /// See: MAVLink [command details](https://mavlink.io/en/guide/xml_schema.html#MAV_CMD) in XML schema docs.
    pub fn is_destination(&self) -> &Option<bool> {
        &self.is_destination
    }

    /// Mission only.
    ///
    /// Apply with value `true` if the MAV_COMMAND only "makes sense" in a mission. For example, the fence mission
    /// commands could not possibly be useful in a command.
    ///
    /// See: MAVLink [command details](https://mavlink.io/en/guide/xml_schema.html#MAV_CMD) in XML schema docs.
    pub fn mission_only(&self) -> &Option<bool> {
        &self.mission_only
    }
}