---
title: "Poll in Rust"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/rust/kernel/poll/
last_updated: 2026-11-18
sdk_version: 4.44
---
# Poll in Rust

Source: https://developer.repebble.com/pebbleos/docs/samples/rust/kernel/poll/

The [poll sample](https://developer.repebble.com/pebbleos/docs/samples/kernel/poll.md) written in [Rust](https://developer.repebble.com/pebbleos/docs/development/build_system/rust.md), on the `pebbleos` crate.

`PollGroup::wait()` returns the queue a message is in, which `is()` compares with each of them.

Run:

`pbl samples samples/rust/kernel/poll`

Boards:

every board

## Sources

src/lib.rs

```
#![no\_std]use core::time::Duration;use pebbleos::msgq::MsgQueue;use pebbleos::poll::PollGroup;use pebbleos::thread::{self, Priority, Thread};use pebbleos::time::Timeout;use pebbleos::{Result, println};#[derive(Clone, Copy)]struct ButtonEvent {button: u8,pressed: bool,}#[derive(Clone, Copy)]struct AccelSample {x: i16,y: i16,z: i16,}// One queue per source, each with its own message type and depth.static BUTTONS: MsgQueue\<ButtonEvent, 4\> = MsgQueue::new();static ACCEL: MsgQueue\<AccelSample, 8\> = MsgQueue::new();static EVENTS: PollGroup = PollGroup::new();static SOURCE: Thread = Thread::new();fn source() -\> Result\<()\> {BUTTONS.put(ButtonEvent {button: 1,pressed: true,},Timeout::FOREVER,)?;thread::sleep(Duration::from\_millis(10));ACCEL.put(AccelSample {x: 10,y: -20,z: 1000,},Timeout::FOREVER,)?;thread::sleep(Duration::from\_millis(10));BUTTONS.put(ButtonEvent {button: 1,pressed: false,},Timeout::FOREVER,)}#[pebbleos::main]fn main() -\> Result\<()\> {// Queues join before the first wait, and for good.EVENTS.add(&BUTTONS);EVENTS.add(&ACCEL);SOURCE.spawn(c"source", Priority::MAIN.lower(1), || {if let Err(e) = source() {println!("source: put failed ({e})");}})?;// The wait leaves the message in its queue.while let Some(q) = EVENTS.wait(Duration::from\_millis(100)) {if q.is(&BUTTONS) {if let Ok(event) = BUTTONS.get(Timeout::NO\_WAIT) {let action = if event.pressed { "pressed" } else { "released" };println!("loop: button {} {action}", event.button);}} else if q.is(&ACCEL)&& let Ok(sample) = ACCEL.get(Timeout::NO\_WAIT){println!("loop: accel {} {} {}", sample.x, sample.y, sample.z);}}println!("loop: nothing for 100 ms");println!("Sample done");Ok(())}
```

## Output

```
loop: button 1 pressed
loop: accel 10 -20 1000
loop: button 1 released
loop: nothing for 100 ms
Sample done
```

Generated from PebbleOS [7753e801d](https://github.com/coredevices/pebbleos/commit/7753e801d93d20f2d37534ce2fa69d9952015237). This page is maintained in the pebbleos repository: [docs/samples/rust/kernel/poll.md](https://github.com/coredevices/pebbleos/blob/7753e801d93d20f2d37534ce2fa69d9952015237/docs/samples/rust/kernel/poll.md).
