#![no_std] #![no_main] use core::time::Duration; use rslibc::{format, print, println, vec, String, Vec}; const FRAMES: [&str; 4] = ["|", "/", "-", "\\"]; const WIDTH: usize = 20; const STEPS: usize = 10; fn bar(done: usize) -> String { let mut out = String::new(); for i in 0..WIDTH { out.push(if i < done { '#' } else { '-' }); } out } fn load(step: usize) -> rslibc::Result { // Pretend to do work and return a checksum-like value. let mut total = 0u32; for value in vec![1, 2, 3, 4, 5] { total = total.wrapping_add(value * step as u32); } Ok(total) } #[rslibc_macros::main] async fn main() { println!("rslibc loading example"); let mut log: Vec = Vec::new(); for step in 0..STEPS { match load(step) { Ok(value) => { let frame = FRAMES[step % FRAMES.len()]; let percent = 100 * (step + 1) / STEPS; print!( "\r [{}] {:>3}% {}", bar((step + 1) * WIDTH / STEPS), percent, frame ); log.push(format!("step {step} -> {value}")); } Err(message) => println!("error: {message}"), } rslibc::runtime::sleep(Duration::from_millis(60)); } println!("\r [{}] 100% done", bar(WIDTH)); println!("log = {log:?}"); }