pub struct Param<C> { /* private fields */ }Expand description
One named f32 field of a config C: how to read it and how to write it, unvalidated.
Implementations§
Source§impl<C> Param<C>
impl<C> Param<C>
Sourcepub const fn new(
name: &'static str,
get: fn(&C) -> f32,
set: fn(&mut C, f32),
) -> Self
pub const fn new( name: &'static str, get: fn(&C) -> f32, set: fn(&mut C, f32), ) -> Self
A param named name, read by get and written (unvalidated) by set, in the param’s
unit. get must read back what set wrote, up to unit-conversion rounding: no
clamping or quantizing (the Params stores-or-rejects contract). Use it to give your
own config a ParamTable:
use stable_flight::params::{Param, ParamTable};
#[derive(Clone, Copy)]
struct TrimConfig {
roll_trim_rad: f32,
}
impl ParamTable for TrimConfig {
const PARAMS: &'static [Param<Self>] = &[Param::new(
"TRIM_ROLL",
|c| c.roll_trim_rad.to_degrees(),
|c, v| c.roll_trim_rad = v.to_radians(),
)];
}
let mut config = TrimConfig { roll_trim_rad: 0.0 };
TrimConfig::PARAMS[0].set(&mut config, 90.0);
assert!((config.roll_trim_rad - core::f32::consts::FRAC_PI_2).abs() < 1e-6);Auto Trait Implementations§
impl<C> Forget for Param<C>
impl<C> Freeze for Param<C>
impl<C> Move for Param<C>
impl<C> RefUnwindSafe for Param<C>
impl<C> Send for Param<C>
impl<C> Sync for Param<C>
impl<C> Unpin for Param<C>
impl<C> UnsafeUnpin for Param<C>
impl<C> UnwindSafe for Param<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.