pub trait Versioned: MaybeVersioned {
// Required methods
fn version() -> MavLinkVersion;
fn ver(&self) -> MavLinkVersion;
fn v() -> Self;
}
Expand description
🔒 Marks entities which have a specified MAVLink protocol version.
âš This trait is sealed âš
Such entities allow to discover their protocol version by Versioned::version
and
provide a static marker
for themselves. This trait also enables converting V1
/ V2
from type parameter to a type by Versioned::v
and to treat them as unit type instances using
Versioned::ver
.
For example, Receiver::versioned
constructs a protocol-specific
receiver which looks up for frames only of a specific dialect.
§Examples
use mavio::prelude::*;
fn release_turbofish<V: Versioned>() {
pass_argument(V::v());
stay_with_enum(V::v().ver());
}
fn pass_argument<V: Versioned>(version: V) {
stay_with_enum(version.ver());
}
fn stay_with_enum(version: MavLinkVersion) {
match version {
MavLinkVersion::V1 => { /* MAVLink1 specific */ }
MavLinkVersion::V2 => { /* MAVLink2 specific */ }
}
}
release_turbofish::<V2>();
pass_argument(V1);
stay_with_enum(MavLinkVersion::V2);
Required Methods§
sourcefn version() -> MavLinkVersion
fn version() -> MavLinkVersion
MAVLink protocol version of a type.
§Examples
use mavio::prelude::*;
fn feed_with_enum(version: MavLinkVersion) {
match version {
MavLinkVersion::V1 => { /* MAVLink1 specific */ }
MavLinkVersion::V2 => { /* MAVLink2 specific */ }
}
}
feed_with_enum(V1::version());
sourcefn ver(&self) -> MavLinkVersion
fn ver(&self) -> MavLinkVersion
MAVLink protocol version of a unit.
Allows to obtain MavLinkVersion
from V1
/ V2
as unit types.
§Examples
use mavio::prelude::*;
fn feed_with_argument<V: Versioned>(version: V) {
feed_with_enum(version.ver());
}
fn feed_with_enum(version: MavLinkVersion) {
match version {
MavLinkVersion::V1 => { /* MAVLink1 specific */ }
MavLinkVersion::V2 => { /* MAVLink1 specific */ }
}
}
feed_with_argument(V1);
sourcefn v() -> Self
fn v() -> Self
Returns MAVLink version as V1
/ V2
for type parameters.
Useful when Versioned
is provided as a type parameter, but you need a corresponding
marker. This allows to switch between regular arguments and turbofish
syntax.
§Examples
use mavio::prelude::*;
fn gimme_argument<V: Versioned>(version: V) {
gimme_turbofish::<V>();
}
fn gimme_turbofish<V: Versioned>() {
// Hard way
match V::version() {
MavLinkVersion::V1 => gimme_argument(V1),
MavLinkVersion::V2 => gimme_argument(V2),
}
// Easy way
gimme_argument(V::v());
}
gimme_argument(V2);
gimme_turbofish::<V2>()