Skip to main content

Actuator

Trait Actuator 

Source
pub trait Actuator {
    type Command;

    // Required method
    fn apply(
        &mut self,
        command: Self::Command,
    ) -> impl Future<Output = Result<()>> + Send;

    // Provided method
    fn map_command<F, C>(self, convert: F) -> MapCommand<Self, F, C>
       where Self: Sized,
             F: FnMut(C) -> Self::Command { ... }
}
Expand description

A sink that accepts typed commands, such as a motor or a valve.

Required Associated Types§

Source

type Command

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

Required Methods§

Source

fn apply( &mut self, command: Self::Command, ) -> impl Future<Output = Result<()>> + Send

Applies a command to the actuator.

§Arguments
  • command - the command to apply, consumed by the call.
§Returns

Ok(()) once the command has been accepted by the actuator.

§Errors

Returns Error::Io if the command cannot be delivered, or Error::Closed if the actuator has been disconnected.

Provided Methods§

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.

This is how a part that takes its own command shape is driven by a consumer that has a simpler one: a profile’s bool becomes a pulse width, a percentage becomes a duty. The result is an Actuator whose command is whatever convert accepts. See MapCommand for an example.

§Arguments
  • convert - the function turning the caller’s command into this part’s.
§Returns

The adapted actuator.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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