examples: Consistently use unwrap! in favor of .unwrap()

Unfortunately errors from `embedded_graphics` and `core` doesn't provide
the necessary instances currently.
This commit is contained in:
Ben Gamari
2021-07-31 11:51:40 -04:00
committed by Dario Nieuwenhuis
parent 36402b5487
commit f4950c4449
22 changed files with 67 additions and 65 deletions

View File

@ -6,7 +6,7 @@
#[path = "../example_common.rs"]
mod example_common;
use defmt::panic;
use defmt::{panic, unwrap};
use embassy::executor::Spawner;
use embassy::traits::rng::Rng as _;
use embassy_nrf::interrupt;
@ -20,14 +20,14 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// Async API
let mut bytes = [0; 4];
rng.fill_bytes(&mut bytes).await.unwrap(); // nRF RNG is infallible
unwrap!(rng.fill_bytes(&mut bytes).await); // nRF RNG is infallible
defmt::info!("Some random bytes: {:?}", bytes);
// Sync API with `rand`
defmt::info!("A random number from 1 to 10: {:?}", rng.gen_range(1..=10));
let mut bytes = [0; 1024];
rng.fill_bytes(&mut bytes).await.unwrap();
unwrap!(rng.fill_bytes(&mut bytes).await);
let zero_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_zeros());
let one_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_ones());
defmt::info!(