Datum

Struct Datum 

Source
pub struct Datum<T> {
    pub time: Time,
    pub value: T,
}
Expand description

A container for a time and something else, usually an f32 or a State.

Fields§

§time: Time

Timestamp for the datum. This should probably be absolute.

§value: T

The thing with the timestamp.

Implementations§

Source§

impl<T> Datum<T>

Source

pub const fn new(time: Time, value: T) -> Datum<T>

Constructor for Datum type.

Examples found in repository?
examples/devices.rs (line 56)
54    fn get(&self) -> Output<State, ()> {
55        println!("Encoder returning state {:?}", STATE);
56        Ok(Some(Datum::new(self.time, STATE)))
57    }
More examples
Hide additional examples
examples/pid.rs (lines 130-133)
129    fn get(&self) -> Output<Quantity, ()> {
130        Ok(Some(Datum::new(
131            self.time,
132            Quantity::from(self.time) * Quantity::new(0.5, MILLIMETER_PER_SECOND),
133        )))
134    }
Source

pub fn replace_if_older_than(&mut self, maybe_replace_with: Self) -> bool

Replaces self with maybe_replace_with if maybe_replace_with’s timestamp is newer than self’s. Returns true if self was replaced and false otherwise.

Trait Implementations§

Source§

impl<T: Add<Output = O>, O> Add<T> for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the + operator.
Source§

fn add(self, other: T) -> Datum<O>

Performs the + operation. Read more
Source§

impl<T: Add<Output = O>, O> Add for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Datum<O>

Performs the + operation. Read more
Source§

impl<T: AddAssign> AddAssign<T> for Datum<T>

Source§

fn add_assign(&mut self, other: T)

Performs the += operation. Read more
Source§

impl<T: AddAssign> AddAssign for Datum<T>

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<T: Clone> Clone for Datum<T>

Source§

fn clone(&self) -> Datum<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Datum<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<Datum<f32>> for Datum<Command>

Source§

type Output = Datum<Command>

The resulting type after applying the / operator.
Source§

fn div(self, other: Datum<f32>) -> Self

Performs the / operation. Read more
Source§

impl Div<Datum<f32>> for Datum<State>

Source§

type Output = Datum<State>

The resulting type after applying the / operator.
Source§

fn div(self, other: Datum<f32>) -> Self

Performs the / operation. Read more
Source§

impl<T: Div<Output = O>, O> Div<T> for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the / operator.
Source§

fn div(self, other: T) -> Datum<O>

Performs the / operation. Read more
Source§

impl Div<f32> for Datum<Command>

Source§

type Output = Datum<Command>

The resulting type after applying the / operator.
Source§

fn div(self, other: f32) -> Self

Performs the / operation. Read more
Source§

impl Div<f32> for Datum<State>

Source§

type Output = Datum<State>

The resulting type after applying the / operator.
Source§

fn div(self, other: f32) -> Self

Performs the / operation. Read more
Source§

impl<T: Div<Output = O>, O> Div for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Datum<O>

Performs the / operation. Read more
Source§

impl DivAssign<Datum<f32>> for Datum<Command>

Source§

fn div_assign(&mut self, other: Datum<f32>)

Performs the /= operation. Read more
Source§

impl DivAssign<Datum<f32>> for Datum<State>

Source§

fn div_assign(&mut self, other: Datum<f32>)

Performs the /= operation. Read more
Source§

impl<T: DivAssign> DivAssign<T> for Datum<T>

Source§

fn div_assign(&mut self, other: T)

Performs the /= operation. Read more
Source§

impl DivAssign<f32> for Datum<Command>

Source§

fn div_assign(&mut self, other: f32)

Performs the /= operation. Read more
Source§

impl DivAssign<f32> for Datum<State>

Source§

fn div_assign(&mut self, other: f32)

Performs the /= operation. Read more
Source§

impl<T: DivAssign> DivAssign for Datum<T>

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl Mul<Datum<f32>> for Datum<Command>

Source§

type Output = Datum<Command>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Datum<f32>) -> Self

Performs the * operation. Read more
Source§

impl Mul<Datum<f32>> for Datum<State>

Source§

type Output = Datum<State>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Datum<f32>) -> Self

Performs the * operation. Read more
Source§

impl<T: Mul<Output = O>, O> Mul<T> for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Datum<O>

Performs the * operation. Read more
Source§

impl Mul<f32> for Datum<Command>

Source§

type Output = Datum<Command>

The resulting type after applying the * operator.
Source§

fn mul(self, other: f32) -> Self

Performs the * operation. Read more
Source§

impl Mul<f32> for Datum<State>

Source§

type Output = Datum<State>

The resulting type after applying the * operator.
Source§

fn mul(self, other: f32) -> Self

Performs the * operation. Read more
Source§

impl<T: Mul<Output = O>, O> Mul for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Datum<O>

Performs the * operation. Read more
Source§

impl MulAssign<Datum<f32>> for Datum<Command>

Source§

fn mul_assign(&mut self, other: Datum<f32>)

Performs the *= operation. Read more
Source§

impl MulAssign<Datum<f32>> for Datum<State>

Source§

fn mul_assign(&mut self, other: Datum<f32>)

Performs the *= operation. Read more
Source§

impl<T: MulAssign> MulAssign<T> for Datum<T>

Source§

fn mul_assign(&mut self, other: T)

Performs the *= operation. Read more
Source§

impl MulAssign<f32> for Datum<Command>

Source§

fn mul_assign(&mut self, other: f32)

Performs the *= operation. Read more
Source§

impl MulAssign<f32> for Datum<State>

Source§

fn mul_assign(&mut self, other: f32)

Performs the *= operation. Read more
Source§

impl<T: MulAssign> MulAssign for Datum<T>

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl<T: Neg<Output = O>, O> Neg for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Datum<O>

Performs the unary - operation. Read more
Source§

impl<T: Not<Output = O>, O> Not for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Datum<O>

Performs the unary ! operation. Read more
Source§

impl<T: PartialEq> PartialEq for Datum<T>

Source§

fn eq(&self, other: &Datum<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<E: Copy + Debug> Settable<Datum<Command>, E> for Terminal<'_, E>

Source§

fn get_settable_data_ref(&self) -> &SettableData<Datum<Command>, 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.
Source§

fn get_settable_data_mut(&mut self) -> &mut SettableData<Datum<Command>, 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.
Source§

fn impl_set(&mut self, _command: Datum<Command>) -> 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.
Source§

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

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

fn stop_following(&mut self)

Stop following the Getter.
Source§

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

fn get_last_request(&self) -> Option<S>

Get the argument from the last time set was called.
Source§

impl<E: Copy + Debug> Settable<Datum<State>, E> for Terminal<'_, E>

Source§

fn get_settable_data_ref(&self) -> &SettableData<Datum<State>, 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.
Source§

fn get_settable_data_mut(&mut self) -> &mut SettableData<Datum<State>, 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.
Source§

fn impl_set(&mut self, _state: Datum<State>) -> 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.
Source§

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

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

fn stop_following(&mut self)

Stop following the Getter.
Source§

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

fn get_last_request(&self) -> Option<S>

Get the argument from the last time set was called.
Source§

impl<T: Sub<Output = O>, O> Sub<T> for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the - operator.
Source§

fn sub(self, other: T) -> Datum<O>

Performs the - operation. Read more
Source§

impl<T: Sub<Output = O>, O> Sub for Datum<T>

Source§

type Output = Datum<O>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Datum<O>

Performs the - operation. Read more
Source§

impl<T: SubAssign> SubAssign<T> for Datum<T>

Source§

fn sub_assign(&mut self, other: T)

Performs the -= operation. Read more
Source§

impl<T: SubAssign> SubAssign for Datum<T>

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl TryFrom<TerminalData> for Datum<Command>

Source§

type Error = ()

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

fn try_from(value: TerminalData) -> Result<Datum<Command>, ()>

Performs the conversion.
Source§

impl TryFrom<TerminalData> for Datum<State>

Source§

type Error = ()

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

fn try_from(value: TerminalData) -> Result<Datum<State>, ()>

Performs the conversion.
Source§

impl<T: Copy> Copy for Datum<T>

Source§

impl<T: Eq> Eq for Datum<T>

Source§

impl<T> StructuralPartialEq for Datum<T>

Auto Trait Implementations§

§

impl<T> Freeze for Datum<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Datum<T>
where T: RefUnwindSafe,

§

impl<T> Send for Datum<T>
where T: Send,

§

impl<T> Sync for Datum<T>
where T: Sync,

§

impl<T> Unpin for Datum<T>
where T: Unpin,

§

impl<T> UnwindSafe for Datum<T>
where T: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.