Skip to main content

Param

Struct Param 

Source
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>

Source

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);
Source

pub fn name(&self) -> &'static str

The param’s name, e.g. "STAB_RATE_RLL_P".

Source

pub fn get(&self, config: &C) -> f32

The param’s value in config, in the param’s unit.

Source

pub fn set(&self, config: &mut C, value: f32)

Writes value (in the param’s unit) into config without validating it.

Auto Trait Implementations§

§

impl<C> Freeze for Param<C>
where fn(&C) -> f32: Freeze, fn(&mut C, f32): Freeze,

§

impl<C> RefUnwindSafe for Param<C>

§

impl<C> Send for Param<C>
where fn(&C) -> f32: Send, fn(&mut C, f32): Send,

§

impl<C> Sync for Param<C>
where fn(&C) -> f32: Sync, fn(&mut C, f32): Sync,

§

impl<C> Unpin for Param<C>
where fn(&C) -> f32: Unpin, fn(&mut C, f32): Unpin,

§

impl<C> UnsafeUnpin for Param<C>

§

impl<C> UnwindSafe for Param<C>

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.