[][src]Struct cmim::Move

pub struct Move<T, I> { /* fields omitted */ }

Move is a structure that is intended to be stored as a static variable, and represents a metaphorical "move" to an interrupt context. Data is moved to the interrupt context by calling try_move from thread (non-interrupt) context, and the data can be retrived within a selected interrupt using the try_lock method.

Methods

impl<T, I> Move<T, I>[src]

pub const fn new_uninitialized(ctxt: Context<I>) -> Self[src]

Create a new Move structure without initializing the data contained by it. This is best used when the data cannot be initialized until runtime, such as a HAL peripheral, or the producer or consumer of a queue.

Before using this in interrupt context, you must initialize it with the try_move function, or it will return errors upon access.

You must provide the context that is allowed to later access this data as the ctxt argument

pub const fn new(data: T, ctxt: Context<I>) -> Self[src]

Create a new Move structure, and initialize the data contained within it. This is best used when the data contained within is const, and doesn't require runtime initialization.

This does not require further interaction before use in interrupt context.

You must provide the context that is allowed to later access this data as the ctxt argument

impl<T, I> Move<T, I> where
    T: Send + Sized,
    I: Nr
[src]

pub fn try_move(&self, data: T) -> Result<Option<T>, T>[src]

Attempt to initialize the data of the Move structure. This MUST be called from non-interrupt context, and a critical section will be in place while setting the data.

Returns:

  • Ok(Some(T)): If we are in thread mode and the data was previously initialized
  • Ok(None): If we are in thread mode and the data was not previously initialized
  • Err(T): If we are not in thread mode (e.g. an interrupt is active), return the data that was going to be moved

pub fn try_free(&self) -> Result<Option<T>, ()>[src]

Attempt to recover the data from the Move structure. This MUST be called from non-interrupt context, and a critical section will be in place while receiving the data.

Returns:

  • Ok(Some(T)): If we are in thread mode and the data was previously initialized
  • Ok(None): If we are in thread mode and the data was not previously initialized
  • Err(()): If we are not in thread mode (e.g. an interrupt is active)

pub fn try_lock<R>(&self, f: impl FnOnce(&mut T) -> R) -> Result<R, ()>[src]

So, this isn't a classical mutex. It will only provide access if:

  • The selected interrupt/exception is currently active
  • The mutex has not already been locked

If these conditions are met, then you can access the variable from within a closure

Trait Implementations

impl<T, I> Sync for Move<T, I> where
    T: Send + Sized,
    I: Nr
[src]

Auto Trait Implementations

impl<T, I> Send for Move<T, I> where
    I: Send,
    T: Send

impl<T, I> Unpin for Move<T, I> where
    I: Unpin,
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.