Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue with capacity 1 is both empty and full #214

Closed
jonas-schievink opened this issue Jun 29, 2021 · 6 comments · Fixed by #215
Closed

Queue with capacity 1 is both empty and full #214

jonas-schievink opened this issue Jun 29, 2021 · 6 comments · Fixed by #215

Comments

@jonas-schievink
Copy link

use heapless::spsc::Queue;

fn main() {
    let queue: Queue<[u8; 16], 1> = Queue::new();
    assert!(queue.is_empty());
    assert!(!queue.is_full());
}
thread 'main' panicked at 'assertion failed: !queue.is_full()', src/main.rs:6:5
@birkenfeld
Copy link
Contributor

From the docs: "A statically allocated single producer single consumer queue with a capacity of N - 1 elements". This is, I think, because the needed const generic math to allocate N + 1 items is not stable yet.

Is it possible to statically assert N > 1?

@jonas-schievink
Copy link
Author

Oh, I see, I missed that

@birkenfeld
Copy link
Contributor

It's new in 0.7 (the first const generics based version).

@burrbull
Copy link
Member

Is it possible to statically assert N > 1?

In nightly only.

@korken89
Copy link
Contributor

Hi, it's possible to do asserts in const with some tricks.
nvzqz/static-assertions#40 (comment)

I'll look into adding them everywhere.

@korken89
Copy link
Contributor

Yeah, the interface is a bit unfortunate.
I hope we get more const power soon so we can get the old interface back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants