embedded-trainings-2020/beginner/apps/src/bin/radio-puzzle-4.rs
Mirabellensaft eec0e0a6bb fix format
2022-01-12 18:05:55 +01:00

38 lines
1 KiB
Rust

#![deny(unused_must_use)]
#![no_main]
#![no_std]
use core::str;
use cortex_m_rt::entry;
use heapless::Vec;
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
use apps as _;
#[entry]
fn main() -> ! {
dk::init().unwrap();
// a buffer with capacity for 2 bytes
let mut buffer = Vec::<u8, 2>::new();
// content type ^^ ^ capacity
// do some insertions
buffer.push(b'H').expect("buffer full");
buffer.push(b'i').expect("buffer full");
// look into the contents so far
defmt::println!("{}", defmt::Debug2Format(&buffer));
// ^^^^^^^^^^^^^^^^^^^ this adapter is currently needed to log
// `StandardRequest` with `defmt`
// or more readable
// NOTE utf-8 conversion works as long as you only push bytes in the ASCII range (0..=127)
defmt::println!(
"{}",
str::from_utf8(&buffer).expect("content was not UTF-8")
);
dk::exit()
}