osal_rs/traits/
queue.rs

1/***************************************************************************
2 *
3 * osal-rs
4 * Copyright (C) 2023/2026 Antonio Salsi <passy.linux@zresa.it>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 *
18 ***************************************************************************/
19
20use crate::os::ToBytes;
21use crate::os::types::{UBaseType, TickType};
22use crate::utils::Result;
23
24
25
26pub trait Queue {
27    fn new (size: UBaseType, message_size: UBaseType) -> Result<Self>
28    where 
29        Self: Sized;
30
31    fn fetch(&self, buffer: &mut [u8], time: TickType) -> Result<()>;
32
33    fn fetch_from_isr(&self, buffer: &mut [u8]) -> Result<()>;
34    
35    fn post(&self, item: &[u8], time: TickType) -> Result<()>;
36    fn post_from_isr(&self, item: &[u8]) -> Result<()>;
37
38    fn delete(&mut self);
39}
40
41pub trait QueueStreamed<T> 
42where 
43    T: ToBytes + Sized {
44
45    fn new (size: UBaseType, message_size: UBaseType) -> Result<Self>
46    where 
47        Self: Sized;
48
49    fn fetch(&self, buffer: &mut T, time: TickType) -> Result<()>;
50
51    fn fetch_from_isr(&self, buffer: &mut T) -> Result<()>;
52    
53    fn post(&self, item: &T, time: TickType) -> Result<()>;
54
55    fn post_from_isr(&self, item: &T) -> Result<()>;
56
57    fn delete(&mut self);
58}