pub trait Settable<S: Clone, E: Copy + Debug>: Updatable<E> {
// Required methods
fn impl_set(&mut self, value: S) -> NothingOrError<E>;
fn get_settable_data_ref(&self) -> &SettableData<S, E>;
fn get_settable_data_mut(&mut self) -> &mut SettableData<S, E>;
// Provided methods
fn set(&mut self, value: S) -> NothingOrError<E> { ... }
fn follow(&mut self, getter: Reference<dyn Getter<S, E>>) { ... }
fn stop_following(&mut self) { ... }
fn update_following_data(&mut self) -> NothingOrError<E> { ... }
fn get_last_request(&self) -> Option<S> { ... }
}Expand description
Something with a set method. Usually used for motors and other mechanical components and
systems. This trait too is fairly broad.
Required Methods§
Sourcefn impl_set(&mut self, value: S) -> NothingOrError<E>
fn impl_set(&mut self, value: S) -> NothingOrError<E>
Set something, not updating the internal SettableData. Due to current limitations of the
language, you must implement this but call set. Do not call this directly as it will make
get_last_request work incorrectly.
Sourcefn get_settable_data_ref(&self) -> &SettableData<S, E>
fn get_settable_data_ref(&self) -> &SettableData<S, E>
As traits cannot have fields, get functions and separate types are required. All you have to
do is make a field for a corresponding SettableData, make this return an immutable
reference to it, and make get_settable_data_mut
return a mutable reference to it.
Sourcefn get_settable_data_mut(&mut self) -> &mut SettableData<S, E>
fn get_settable_data_mut(&mut self) -> &mut SettableData<S, E>
As traits cannot have fields, get functions and separate types are required. All you have to
do is make a field for a corresponding SettableData, make this return a mutable
reference to it, and make get_settable_data_ref
return an immutable reference to it.
Provided Methods§
Sourcefn set(&mut self, value: S) -> NothingOrError<E>
fn set(&mut self, value: S) -> NothingOrError<E>
Set something to a value. For example, this could set a motor to a voltage. You should call
this and not impl_set.
Sourcefn follow(&mut self, getter: Reference<dyn Getter<S, E>>)
fn follow(&mut self, getter: Reference<dyn Getter<S, E>>)
Begin following a Getter of the same type. For this to work, you must have
update_following_data in your Updatable implementation.
Sourcefn stop_following(&mut self)
fn stop_following(&mut self)
Stop following the Getter.
Sourcefn update_following_data(&mut self) -> NothingOrError<E>
fn update_following_data(&mut self) -> NothingOrError<E>
Get a new value from the Getter we’re following, if there is one, and call
set
accordingly. You must add this to your Updatable implementation if you are following
Getters. This is a current limitation of the Rust language. If specialization is ever
stabilized, this will hopefully be done in a better way.
Sourcefn get_last_request(&self) -> Option<S>
fn get_last_request(&self) -> Option<S>
Get the argument from the last time set was called.