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 implementToBytes,BytesHasLen, andFromBytes
§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,
impl<T> QueueStreamed<T>where
T: StructSerde,
Trait Implementations§
Source§impl<T> Debug for QueueStreamed<T>where
T: StructSerde,
Formats the typed queue for debugging purposes.
impl<T> Debug for QueueStreamed<T>where
T: StructSerde,
Formats the typed queue for debugging purposes.
Source§impl<T> Deref for QueueStreamed<T>where
T: StructSerde,
Allows dereferencing to the underlying FreeRTOS queue handle.
impl<T> Deref for QueueStreamed<T>where
T: StructSerde,
Allows dereferencing to the underlying FreeRTOS queue handle.
Source§impl<T> Display for QueueStreamed<T>where
T: StructSerde,
Formats the typed queue for display purposes.
impl<T> Display for QueueStreamed<T>where
T: StructSerde,
Formats the typed queue for display purposes.
Source§impl<T> QueueStreamed<T> for QueueStreamed<T>where
T: StructSerde,
Available on non-crate feature serde only.
impl<T> QueueStreamed<T> for QueueStreamed<T>where
T: StructSerde,
serde only.Source§fn fetch(&self, buffer: &mut T, time: TickType) -> Result<()>
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 messagetime- Timeout in system ticks
§Returns
Ok(())- Message successfully received and deserializedErr(Error::Timeout)- Queue empty or timeoutErr(Error)- Deserialization error
Source§fn fetch_from_isr(&self, buffer: &mut T) -> Result<()>
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 deserializedErr(Error::Timeout)- Queue is emptyErr(Error)- Deserialization error
§Safety
Must only be called from ISR context.
Source§fn post(&self, item: &T, time: TickType) -> Result<()>
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 sendtime- Timeout in system ticks
§Returns
Ok(())- Message successfully serialized and sentErr(Error::Timeout)- Queue fullErr(Error)- Serialization error
Source§fn post_from_isr(&self, item: &T) -> Result<()>
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 sentErr(Error::Timeout)- Queue is fullErr(Error)- Serialization error
§Safety
Must only be called from ISR context.