pub struct QueueStreamed<T: StructSerde>(/* private fields */);Expand description
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,
impl<T> Debug for QueueStreamed<T>where
T: StructSerde,
Source§impl<T> Deref for QueueStreamed<T>where
T: StructSerde,
impl<T> Deref for QueueStreamed<T>where
T: StructSerde,
Source§impl<T> Display for QueueStreamed<T>where
T: StructSerde,
impl<T> Display for QueueStreamed<T>where
T: StructSerde,
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,
Available on non-crate feature
serde only.Source§fn fetch(&self, buffer: &mut T, time: TickType) -> Result<()>
fn fetch(&self, buffer: &mut T, time: TickType) -> Result<()>
Fetches a typed message from the queue (blocking). Read more
Source§fn fetch_from_isr(&self, buffer: &mut T) -> Result<()>
fn fetch_from_isr(&self, buffer: &mut T) -> Result<()>
Fetches a typed message from ISR context (non-blocking). Read more
Source§fn post(&self, item: &T, time: TickType) -> Result<()>
fn post(&self, item: &T, time: TickType) -> Result<()>
Posts a typed message to the queue (blocking). Read more
impl<T: StructSerde> Send for QueueStreamed<T>
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> UnwindSafe for QueueStreamed<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more