Skip to main content

QueueStreamed

Struct QueueStreamed 

Source
pub struct QueueStreamed<T: StructSerde>(/* private fields */);
Expand description

Queue types for inter-task communication. Type-safe wrapper around Queue that (de)serializes T instead of requiring callers to shuffle raw byte slices themselves.

T must implement BytesHasLen + Serialize + Deserialize (bundled together as StructSerde) - or, with the serde feature enabled, whatever osal-rs-serde’s derive macros provide instead.

§Examples

use osal_rs::os::*;

#[derive(Clone)]
struct Reading(u32);

impl BytesHasLen for Reading {
    fn len(&self) -> usize { core::mem::size_of::<u32>() }
}

impl Serialize for Reading {
    fn to_bytes(&self) -> &[u8] {
        unsafe {
            core::slice::from_raw_parts(&self.0 as *const u32 as *const u8, core::mem::size_of::<u32>())
        }
    }
}

impl Deserialize for Reading {
    fn from_bytes(bytes: &[u8]) -> osal_rs::utils::Result<Self> {
        let mut buf = [0u8; 4];
        buf.copy_from_slice(&bytes[..4]);
        Ok(Reading(u32::from_le_bytes(buf)))
    }
}

let queue = QueueStreamed::<Reading>::new(4, 4).unwrap();
queue.post(&Reading(42), 100).unwrap();

let mut out = Reading(0);
queue.fetch(&mut out, 100).unwrap();
assert_eq!(out.0, 42);

Implementations§

Source§

impl<T> QueueStreamed<T>
where T: StructSerde,

Source

pub fn new(size: UBaseType, message_size: UBaseType) -> Result<Self>

Creates a streamed queue holding up to size messages of message_size bytes each - same capacity semantics as Queue::new, just typed as T instead of raw bytes.

See the type-level example for a complete, testable usage.

Methods from Deref<Target = QueueHandle>§

Source

pub fn is_empty(&self) -> bool

Returns true if this handle is still in its never-initialized (or already-deleted) state, i.e. both the mutex and condition variable are all-zero.

§Examples
use osal_rs::os::types::ClockMonotonicHandle;

assert!(ClockMonotonicHandle::default().is_empty());

Trait Implementations§

Source§

impl<T> Debug for QueueStreamed<T>
where T: StructSerde,

Source§

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

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

impl<T> Deref for QueueStreamed<T>
where T: StructSerde,

Source§

type Target = ClockMonotonicHandle

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> Display for QueueStreamed<T>
where T: StructSerde,

Source§

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

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

impl<T> QueueStreamed<T> for QueueStreamed<T>
where T: StructSerde,

Available on crate feature serde only.
Source§

fn fetch(&self, buffer: &mut T, time: TickType) -> Result<()>

Blocks like Queue::fetch, deserializing the received bytes into buffer via osal-rs-serde.

Source§

fn fetch_from_isr(&self, buffer: &mut T) -> Result<()>

Source§

fn post(&self, item: &T, time: TickType) -> Result<()>

Blocks like Queue::post, serializing item via osal-rs-serde first.

Source§

fn post_from_isr(&self, item: &T) -> Result<()>

ISR-safe variant of QueueStreamedFn::post; see Queue::post_from_isr.

Source§

fn delete(&mut self)

Destroys the underlying queue; see Queue::delete.

Source§

impl<T: StructSerde> Send for QueueStreamed<T>

Source§

impl<T: StructSerde> Sync for QueueStreamed<T>

Auto Trait Implementations§

§

impl<T> !Freeze for QueueStreamed<T>

§

impl<T> !RefUnwindSafe for QueueStreamed<T>

§

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

§

impl<T> UnsafeUnpin for QueueStreamed<T>

§

impl<T> UnwindSafe for QueueStreamed<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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.