pub struct TokenParts<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> { /* private fields */ }
Expand description

A StartToken that has possibly already lost some of its properties.

Note that while this item shows up in the documentation, the type is actually hidden and only named as StartToken. This ensures that more properties can be added compatibly (because no user ever names the type and would thus run into conflicts when the list of generics grows). This has the downside that TokenParts can not easily be passed to downstream functions, and all splitting has to happen at the top level; this should not be a problem in practice.

The individual parameters are:

  • MSG_SEMANTICS: If this is true, the thread has not assigned semantics to messages it would receive yet.
  • MSG_QUEUE: If this is true, the thread has not yet set up a message queue.
  • FLAG_SEMANTICS: If this is true, the thread has not assigned semantics to flags yet.

(FLAG_SEMANTICS are not used yet, but are already prepared for a wrapper similar to msg::v2).

Implementations§

source§

impl TokenParts<true, true, true>

source

pub unsafe fn new() -> Self

Claim that the current thread has not done anything yet that is covered by this type

Do not call yourself; this needs to be public because riot_main_with_tokens! is a macro and thus technically called from the main crate.

source§

impl<const MS: bool, const MQ: bool, const FS: bool> TokenParts<MS, MQ, FS>

source

pub fn in_thread(&self) -> InThread

Extract a token that states that code that has access to it is running in a thread (and not in an interrupt).

source§

impl<const MQ: bool, const FS: bool> TokenParts<true, MQ, FS>

source

pub fn take_msg_semantics( self ) -> (TokenParts<false, MQ, FS>, NoConfiguredMessages)

Available on crate feature with_msg_v2 only.

Extract the claim that the thread was not previously configured with any messages that would be sent to it.

§Example
fn thread(tok: StartToken) -> EndToken {
    let (tok, semantics) = tok.take_msg_semantics();
    // keep working with semantics and start receiving messages
    //
    // receive messages
    //
    // recover semantics when everyone has returned the license to send messages
    let tok = tok.return_msg_semantics(semantics);
    tok.can_end()
}
source§

impl<const MQ: bool, const FS: bool> TokenParts<false, MQ, FS>

source

pub fn return_msg_semantics( self, semantics: NoConfiguredMessages ) -> TokenParts<true, MQ, FS>

Available on crate feature with_msg_v2 only.

Inverse of TokenParts::take_msg_semantics, indicating that the thread may be terminated again as far as message semantics are concerned.

source§

impl<const MS: bool, const FS: bool> TokenParts<MS, true, FS>

source

pub fn with_message_queue<const N: usize, F: FnOnce(TokenParts<MS, false, FS>) -> !>( self, f: F ) -> !

Set up a message queue of given size N, and run the function f after that has been set up. f gets passed all the remaining thread invariants.

As this doesn’t deal with the message semantics, it can’t be sure whether at function return time all other system components have stopped sending messages; the easy way out is to require the function to diverge.

§Example
fn thread(tok: StartToken) -> EndToken {
    tok.with_message_queue::<4, _>(|tok| {
        loop {
            // ...
        }
    })
}
source§

impl<const MQ: bool> TokenParts<true, MQ, true>

source

pub fn can_end(self) -> EndToken

Certify that nothing has been done in this thread that precludes the termination of the thread

MessageSemantics need to have been returned (or never taken) for the next thread on this PID would get weird messages.

The MessageQueue is not checked for – as all MessageSemantics have been returned (and thus nothing can safely send messages any more), even if there is a queue somewhere on the stack, it wouldn’t be touched by others any more. (Of course, that’s moot with the current mechanism of TokenParts::with_message_queue() as that diverges anyway).

source

pub fn termination(self) -> EndToken

👎Deprecated: Renamed to can_end

Auto Trait Implementations§

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> RefUnwindSafe for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> !Send for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> !Sync for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> Unpin for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> UnwindSafe for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

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> IntoSwitch for T

source§

fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more
source§

fn into_active_low_switch(self) -> Switch<Self, ActiveLow>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more
source§

fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.