From 97f915164594c3e88340b2c5c94541e544a4e7ad Mon Sep 17 00:00:00 2001 From: 97gushan <97gustavh@gmail.com> Date: Tue, 18 Feb 2020 14:26:11 +0100 Subject: [PATCH] bare3 0-2 --- examples/bare3.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/bare3.rs b/examples/bare3.rs index 665b4da..9f41ec0 100644 --- a/examples/bare3.rs +++ b/examples/bare3.rs @@ -18,25 +18,25 @@ use cortex_m_semihosting::{hprint, hprintln}; #[entry] fn main() -> ! { hprintln!("bare3").unwrap(); - let s = "ABCD"; - let bs = s.as_bytes(); + let s: &str = "ABCD"; + let bs: &[u8] = s.as_bytes(); hprintln!("s = {}", s).unwrap(); hprintln!("bs = {:?}", bs).unwrap(); hprintln!("iterate over slice").unwrap(); for c in bs { - hprint!("{},", c).unwrap(); + hprint!("{},", c as &u8).unwrap(); } hprintln!("iterate iterate using (raw) indexing").unwrap(); - for i in 0..s.len() { + for i in 0usize..s.len() { hprintln!("{},", bs[i]).unwrap(); } hprintln!("").unwrap(); - let a = [65u8; 4]; + let a: [u8; 4] = [65u8; 4]; // let mut a = [0u8; 4]; hprintln!("").unwrap(); @@ -54,27 +54,37 @@ fn main() -> ! { // // 1. What is the output in the `openocd` (Adapter Output) console? // -// ** your answer here ** +// s = ABCD +// bs = [65, 66, 67, 68] +// iterate over slice +// 65,66,67,68,iterate iterate using (raw) indexing +// 65, +// 66, +// 67, +// 68, + + +// a = AAAA // // What is the type of `s`? // -// ** your answer here ** +// &str // // What is the type of `bs`? // -// ** your answer here ** +// &[u8] // // What is the type of `c`? // -// ** your answer here ** +// &u8 // // What is the type of `a`? // -// ** your answer here ** +// [u8; 4] // // What is the type of `i`? // -// ** your answer here ** +// usize // // Commit your answers (bare3_1) // -- GitLab