Main function
Section |
---|
Main function |
Async Main Function |
TODO
use std::fs::File; use std::io::Read; use anyhow::anyhow; use anyhow::Result; fn read_uptime() -> Result<u64> { let mut uptime = String::new(); File::open("/proc/uptime")?.read_to_string(&mut uptime)?; Ok(uptime .split('.') .next() .ok_or(anyhow!("Cannot parse uptime data"))? .parse()?) } fn main() { match read_uptime() { Ok(uptime) => println!("uptime: {} seconds", uptime), Err(err) => eprintln!("error: {}", err), }; }
Async Main Function
use anyhow::Result; #[tokio::main] async fn main() -> Result<()> { println!("I'm async!"); Ok(()) }
TODO: add text
async main