Skip to main content

QueueStreamed

Struct QueueStreamed 

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

Queue types for inter-task communication. A type-safe FIFO queue for message passing.

Unlike Queue, which works with raw byte slices, QueueStreamed provides a type-safe interface for sending and receiving structured data. The type must implement serialization traits.

§Type Parameters

  • T - The message type. Must implement ToBytes, BytesHasLen, and FromBytes

§Examples

§Basic typed queue usage

use osal_rs::os::{QueueStreamed, QueueStreamedFn};
use core::time::Duration;
 
#[derive(Debug, Clone, Copy)]
struct Message {
    id: u32,
    value: i16,
}
 
// Assuming Message implements the required traits
let queue: QueueStreamed<Message> = QueueStreamed::new(10, size_of::<Message>()).unwrap();
 
// Send a message
let msg = Message { id: 1, value: 42 };
queue.post_with_to_tick(&msg, Duration::from_millis(100)).unwrap();
 
// Receive a message
let mut received = Message { id: 0, value: 0 };
queue.fetch_with_to_tick(&mut received, Duration::from_millis(100)).unwrap();
assert_eq!(received.id, 1);
assert_eq!(received.value, 42);

§Command queue pattern

use osal_rs::os::{QueueStreamed, Thread};
use alloc::sync::Arc;
 
enum Command {
    Start,
    Stop,
    SetValue(u32),
}
 
let cmd_queue = Arc::new(QueueStreamed::<Command>::new(10, 8).unwrap());
let queue_clone = cmd_queue.clone();
 
let handler = Thread::new("handler", 2048, 5, move || {
    loop {
        let mut cmd = Command::Stop;
        if queue_clone.fetch(&mut cmd, 1000).is_ok() {
            match cmd {
                Command::Start => { /* start operation */ },
                Command::Stop => { /* stop operation */ },
                Command::SetValue(val) => { /* set value */ },
            }
        }
    }
}).unwrap();

Implementations§

Source§

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

Source

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

Creates a new type-safe queue.

§Parameters
  • size - Maximum number of messages
  • message_size - Size of each message (typically size_of::<T>())
§Returns
  • Ok(Self) - Successfully created queue
  • Err(Error) - Creation failed

Trait Implementations§

Source§

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

Formats the typed queue for debugging purposes.

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,

Allows dereferencing to the underlying FreeRTOS queue handle.

Source§

type Target = *const c_void

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

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

Formats the typed queue for display purposes.

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 non-crate feature serde only.
Source§

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

Receives a typed message from the queue (without serde feature).

Deserializes the message from bytes using the custom serialization traits.

§Arguments
  • buffer - Mutable reference to receive the deserialized message
  • time - Timeout in system ticks
§Returns
  • Ok(()) - Message successfully received and deserialized
  • Err(Error::Timeout) - Queue empty or timeout
  • Err(Error) - Deserialization error
Source§

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

Receives a typed message from ISR context (without serde feature).

ISR-safe version that does not block. Deserializes the message from bytes.

§Arguments
  • buffer - Mutable reference to receive the deserialized message
§Returns
  • Ok(()) - Message successfully received and deserialized
  • Err(Error::Timeout) - Queue is empty
  • Err(Error) - Deserialization error
§Safety

Must only be called from ISR context.

Source§

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

Sends a typed message to the queue (without serde feature).

Serializes the message to bytes using the custom serialization traits.

§Arguments
  • item - Reference to the message to send
  • time - Timeout in system ticks
§Returns
  • Ok(()) - Message successfully serialized and sent
  • Err(Error::Timeout) - Queue full
  • Err(Error) - Serialization error
Source§

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

Sends a typed message from ISR context (without serde feature).

ISR-safe version that does not block. Serializes the message to bytes.

§Arguments
  • item - Reference to the message to send
§Returns
  • Ok(()) - Message successfully serialized and sent
  • Err(Error::Timeout) - Queue is full
  • Err(Error) - Serialization error
§Safety

Must only be called from ISR context.

Source§

fn delete(&mut self)

Deletes the typed queue.

Delegates to the underlying byte queue’s delete method.

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>
where T: RefUnwindSafe,

§

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.