Struct mavinspect::protocol::Filter

source ·
pub struct Filter { /* private fields */ }
Expand description

Filter options for Dialect and Protocol.

Filters messages, commands, and enums by the following filters:

In the case of Filter::messages, Filter::enums, and Filter::commands, if Filter::microservices is specified, then these entities will be retained in addition to micro-services specification.

Both Filter::messages, Filter::enums, and Filter::commands support wildcards in postfix positions. For example, * and MAV_CMD_DO_* are both valid specifications.

The decision of which enums and their entries to keep is based on whether enum is referenced in MessageField or it was referenced by another already included enum in one of the enum parameters (EnumEntryMavCmdParam).

Micro-service specifications are similar to filters and have Microservices::messages, Microservices::enums, and Microservices::commands methods that provide lists of required entities.

§Usage

use mavinspect::protocol::{Filter, Microservices};

/* obtain protocol with `common` dialect */

// Filter
let filtered_protocol = protocol.filtered(
    &Filter::by_microservices(Microservices::HEARTBEAT | Microservices::MISSION)
    .with_messages(&["FILE_TRANSFER_PROTOCOL"])
    .with_enums(&["GIMBAL_DEVICE_CAP_FLAGS"])
    .with_commands(&["MAV_CMD_SET_*"])
);

// Let's inspect `common` dialect
let common = filtered_protocol.get_dialect_by_canonical_name("common").unwrap();

// it should contain `HEARTBEAT` messages
assert!(common.contains_message_with_name("HEARTBEAT"));
// and `COMMAND_LONG` message since `MISSION` microservice depends on some commands
assert!(common.contains_message_with_name("COMMAND_LONG"));
// `FILE_TRANSFER_PROTOCOL` (part of file transfer protocol) was explicitly required by `set_messages`
assert!(common.contains_message_with_name("FILE_TRANSFER_PROTOCOL"));

// but these messages should be filtered out
assert!(!common.contains_message_with_name("PROTOCOL_VERSION"));
assert!(!common.contains_message_with_name("CAMERA_TRIGGER"));

// this enum was explicitly requested
assert!(common.contains_enum_with_name("GIMBAL_DEVICE_CAP_FLAGS"));
// since we have commands, then `MAV_CMD` enum should be present
assert!(common.contains_enum_with_name("MAV_CMD"));
// and this command was explicitly requested by `MAV_CMD_SET_*` pattern
assert!(common.contains_command_with_name("MAV_CMD_SET_MESSAGE_INTERVAL"));
// as well as these commands should be present as a part of mission protocol
assert!(common.contains_command_with_name("MAV_CMD_DO_SET_MISSION_CURRENT"));
assert!(common.contains_command_with_name("MAV_CMD_NAV_WAYPOINT"));
// but not these
assert!(!common.contains_command_with_name("MAV_CMD_INJECT_FAILURE"));
assert!(!common.contains_command_with_name("MAV_CMD_GET_HOME_POSITION"));

Implementations§

source§

impl Filter

source

pub fn new() -> Self

Default constructor.

source

pub fn by_microservices(microservices: Microservices) -> Self

Constructs Filter that filter by specified microservices.

source

pub fn messages(&self) -> Option<&[impl AsRef<str>]>

Messages to filter.

source

pub fn enums(&self) -> Option<&[impl AsRef<str>]>

Enums to filter.

source

pub fn commands(&self) -> Option<&[impl AsRef<str>]>

Commands to filter.

source

pub fn microservices(&self) -> Option<Microservices>

Microservices to filter.

source

pub fn with_messages(self, messages: &[impl AsRef<str>]) -> Self

Set Self::messages filter option.

source

pub fn with_enums(self, enums: &[impl ToString]) -> Self

Set Self::enums filter option.

source

pub fn with_commands(self, commands: &[impl ToString]) -> Self

Set Self::commands filter option.

source

pub fn with_microservices(self, microservices: Microservices) -> Self

Set Self::microservices filter option.

source

pub fn is_some(&self) -> bool

Returns true if at least one filter is set.

source

pub fn is_none(&self) -> bool

Returns true if no filters are set.

Trait Implementations§

source§

impl Clone for Filter

source§

fn clone(&self) -> Filter

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Filter

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Filter

source§

fn default() -> Filter

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Filter

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Filter

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Filter

§

impl RefUnwindSafe for Filter

§

impl Send for Filter

§

impl Sync for Filter

§

impl Unpin for Filter

§

impl UnwindSafe for Filter

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,