Skip to content

Commit

Permalink
Queue shouldn't require Copy
Browse files Browse the repository at this point in the history
By requiring items to be `Copy` we reduce the queue to only work with
primitives. But, queue dosn't require `Copy` to send items. Yes, they
are technically copied over to the Queue buffer, but semantically this
is a move, and having `send()` consume it's argument provides the move
semantics.
  • Loading branch information
eivindbergem committed Aug 23, 2024
1 parent 59b0a36 commit 3d5d80e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions freertos-rust/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ use crate::prelude::v1::*;
use crate::shim::*;
use crate::units::*;

unsafe impl<T: Sized + Copy> Send for Queue<T> {}
unsafe impl<T: Sized + Copy> Sync for Queue<T> {}
unsafe impl<T: Sized> Send for Queue<T> {}
unsafe impl<T: Sized> Sync for Queue<T> {}

/// A queue with a finite size. The items are owned by the queue and are
/// copied.
/// A queue with a finite size.
#[derive(Debug)]
pub struct Queue<T: Sized + Copy> {
pub struct Queue<T: Sized> {
queue: FreeRtosQueueHandle,
item_type: PhantomData<T>,
}

impl<T: Sized + Copy> Queue<T> {
impl<T: Sized> Queue<T> {
pub fn new(max_size: usize) -> Result<Queue<T>, FreeRtosError> {
let item_size = mem::size_of::<T>();

Expand Down Expand Up @@ -107,7 +106,7 @@ impl<T: Sized + Copy> Queue<T> {
}
}

impl<T: Sized + Copy> Drop for Queue<T> {
impl<T: Sized> Drop for Queue<T> {
fn drop(&mut self) {
unsafe {
freertos_rs_queue_delete(self.queue);
Expand Down

0 comments on commit 3d5d80e

Please sign in to comment.