Skip to main content

MapCommand

Struct MapCommand 

Source
pub struct MapCommand<A, F, C> { /* private fields */ }
Expand description

An actuator whose commands are converted before they reach the part.

Created by Actuator::map_command. The function runs on every command, so a part that takes a pulse width or a duty can be driven by a bool, an angle, or a percentage, whichever the caller has.

§Examples

use pamoja_core::{Actuator, Result};

struct Pump {
    duty: u8,
}
impl Actuator for Pump {
    type Command = u8;
    async fn apply(&mut self, duty: u8) -> Result<()> {
        self.duty = duty;
        Ok(())
    }
}

// A profile drives the pump as on or off; on means full speed.
let mut switch = Pump { duty: 0 }.map_command(|on: bool| if on { 100 } else { 0 });
switch.apply(true).await?;
assert_eq!(switch.inner().duty, 100);

Implementations§

Source§

impl<A, F, C> MapCommand<A, F, C>

Source

pub fn new(inner: A, convert: F) -> MapCommand<A, F, C>

Wraps inner so each command passes through convert first.

§Arguments
  • inner - the actuator being adapted.
  • convert - the function turning the caller’s command into the part’s.
§Returns

The adapted actuator.

Source

pub fn inner(&self) -> &A

Borrows the wrapped actuator.

§Returns

The actuator underneath the adapter.

Source

pub fn inner_mut(&mut self) -> &mut A

Mutably borrows the wrapped actuator.

§Returns

The actuator underneath the adapter.

Source

pub fn into_inner(self) -> A

Unwraps the actuator, discarding the adapter.

§Returns

The actuator underneath the adapter.

Trait Implementations§

Source§

impl<A, F, C> Actuator for MapCommand<A, F, C>
where A: Actuator + Send, F: FnMut(C) -> A::Command + Send, C: Send,

Source§

type Command = C

The command accepted by a single application, for example a setpoint.
Source§

async fn apply(&mut self, command: C) -> Result<()>

Applies a command to the actuator. Read more
Source§

fn map_command<F, C>(self, convert: F) -> MapCommand<Self, F, C>
where Self: Sized, F: FnMut(C) -> Self::Command,

Wraps this actuator so every command passes through convert first. Read more

Auto Trait Implementations§

§

impl<A, F, C> Freeze for MapCommand<A, F, C>
where A: Freeze, F: Freeze,

§

impl<A, F, C> RefUnwindSafe for MapCommand<A, F, C>

§

impl<A, F, C> Send for MapCommand<A, F, C>
where A: Send, F: Send,

§

impl<A, F, C> Sync for MapCommand<A, F, C>
where A: Sync, F: Sync,

§

impl<A, F, C> Unpin for MapCommand<A, F, C>
where A: Unpin, F: Unpin,

§

impl<A, F, C> UnsafeUnpin for MapCommand<A, F, C>
where A: UnsafeUnpin, F: UnsafeUnpin,

§

impl<A, F, C> UnwindSafe for MapCommand<A, F, C>
where A: UnwindSafe, F: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.